在VB6中将字符串替换为定义变量

在VB6中将字符串替换为定义变量,vb6,Vb6,我有替换预定变量字符串的代码,但我的代码似乎效率不高,因为如果需要替换的字符串越多,替换函数就越多,我该如何处理 Dim appName As String Dim appVer As String Dim desc As String appName = "MyProject" appVer = App.Major & "." & App.Minor & "." & App.Revision desc = "{appName} {appVer} is free

我有替换预定变量字符串的代码,但我的代码似乎效率不高,因为如果需要替换的字符串越多,替换函数就越多,我该如何处理

Dim appName As String
Dim appVer As String
Dim desc As String
appName = "MyProject"
appVer = App.Major & "." & App.Minor & "." & App.Revision
desc = "{appName} {appVer} is free program"
desc = Replace(desc, "{appName}", appName)
desc = Replace(desc, "{appVer}", appVer)
Label1.Caption = desc
谢谢你的帮助我回答我的问题

Public Function ReplaceString(sString As String) As String
Const Tag1 = "{"
Const Tag2 = "}"
Dim sItem() As String, i As Long

sString = Replace(sString, "\n", vbNewLine) 'Replace new line

sItem = Split(sString, Tag1)
For i = 1 To UBound(sItem)
   sItem(i - 1) = Split(sItem(i), Tag2, 2)(0)
Next

ReDim Preserve sItem(UBound(sItem) - 1)
   For i = 0 To UBound(sItem)
      sString = Replace(sString, "{" & sItem(i) & "}", CallByName(Me, sItem(i), VbGet))
   Next
ReplaceString = sString
End Function

希望这能在同样的情况下对其他人有所帮助

desc=appName&&&appVer&“是免费程序”
?事实上,我将对我的“desc”字符串使用多语言,是否可以将replace转换为自定义函数?这是否回答了您的问题?我认为这是一个聪明的方法,虽然它的工作原理中也有一点“隐藏”。这将在我的multilang应用程序中使用,它是res文件中的lang字符串存储,所以只需使用“{appVersion}或{appName}或其他动态值替换它”