STRCONV把括号作为第一个字母

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功能可以做同样的事情

:微软的VBScript正则表达式5.5)的引用

  1. 方法1 - >此将替换左括号
  2. 方法2 - >此将取代左/右括号

方法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

以上是 STRCONV把括号作为第一个字母 的全部内容, 来源链接: utcz.com/qa/267221.html

回到顶部