STRCONV在下面的回報 (HELLO WORLD)的代碼 而不是期望 (你好世界) 因爲它把第一個括號爲單詞「HELLO」的第一個字母。 任何人都可以建議如何克服這個問題嗎?STRCONV把括號作爲第一個字母
Dim MyString
Dim MyCaseString
MyString = "(HELLO WORLD)"
MyCaseString = strConv(MyString, 3)
MsgBox MyCaseString
STRCONV在下面的回報 (HELLO WORLD)的代碼 而不是期望 (你好世界) 因爲它把第一個括號爲單詞「HELLO」的第一個字母。 任何人都可以建議如何克服這個問題嗎?STRCONV把括號作爲第一個字母
Dim MyString
Dim MyCaseString
MyString = "(HELLO WORLD)"
MyCaseString = strConv(MyString, 3)
MsgBox MyCaseString
使用MID()來切掉領先「(」 - 可以添加回:
Sub test()
Dim MyString
Dim MyCaseString
MyString = "(HELLO WORLD)"
MyCaseString = "(" & StrConv(Mid(MyString, 2), 3)
MsgBox MyCaseString
End Sub
我個人用正則表達式做到這一點(你需要。
Dim regex As New RegExp
Dim matches As MatchCollection
Dim word As Match
Dim sample As String
sample = "(HELLO WORLD)"
With regex
.Pattern = "\w+"
.Global = True
Set matches = .Execute(sample)
End With
For Each word In matches
sample = Replace$(sample, word, StrConv(word, vbProperCase))
Next word
Debug.Print sample
謝謝共產國際。這看起來確實很有趣。我會盡力從明天開始學習。非常感謝你。 –
如約翰·科爾曼,使用Replace
功能可以做同樣的事情
方法1:
Sub Test1()
Dim MyString
Dim MyCaseString
MyString = "(HELLO WORLD)"
MyCaseString = "(" & StrConv(Replace(MyString, "(", ""), 3)
MsgBox MyCaseString
End Sub
方法2:
Sub Test2()
Dim MyString
Dim MyCaseString
MyString = "(HELLO WORLD)"
mystr = Replace(Replace(MyString, "(", ""), ")", "")
MyCaseString = "(" & StrConv(mystr, vbProperCase) & ")"
MsgBox MyCaseString
End Sub
非常感謝John Coleman。完美的作品。我非常感謝你。 –