我有一个包含多个特殊字符的字符串,我希望将它与特殊字符分开。
示例:
s = "apple+onion*abc/ki&jk"
输出:
apple
onion
abc
ki
jk
答案 0 :(得分:3)
你可以这样做:
Dim s : s = "apple+onion*abc/ki&jk"
Dim r : Set r = New RegExp
r.Global = True
r.Pattern = "\+|\*|&|®|@|/"
NewString = r.Replace(s,"_")
wscript.echo NewString
Tab = Split(NewString,"_")
For i=LBound(Tab) to Ubound(Tab)
Msg = Msg & Tab(i) & vbCrlf
Next
wscript.echo Msg
答案 1 :(得分:2)
另一种方法,这只是略微改变正则表达式
strPhrase = "apple+onion*abc/ki&jk"
Set objRegEx = CreateObject("vbscript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = "[^a-z0-9]"
ReplacedText = objRegEx.Replace(strPhrase, " ")
objArr = Split(ReplacedText)
For i = 0 To UBound(objArr)
If Trim(objArr(i)) <> "" Then
Debug.Print objArr(i)
End If
Next
Set objRegEx = Nothing
答案 2 :(得分:1)
这也是拆分字符串的方法之一..
Array
(
[4] => Array
(
[item_value] => Coaching
[hours] => 999.99
)
[1487] => Array
(
[item_value] => Standby
[hours] => 15
)
[1488] => Array
(
[item_value] => Standby
[hours] => 40
)
)