如果你願意砸,並使用正則表達式:
Option Explicit
Dim args : Set args = WScript.Arguments.Unnamed
If args.Count < 1 then
WScript.Echo "Error no arguments selected - usage: script.vbs <SERVERNAME>:<PORT> <SERVERNAME>:<PORT> <SERVERNAME>:<PORT> etc"
WScript.Quit
Else
Dim r : Set r = New RegExp
r.Pattern = "^\w+:\d+$"
Dim a, m
For Each a In args
Set m = r.Execute(a)
If 1 <> m.Count Then
WScript.Echo "Bingo:", a
Else
WScript.Echo "setup.exe", m(0).Value
End If
Next
End If
輸出:
cscript y.vbs
Error no arguments selected - usage: script.vbs <SERVERNAME>:<PORT> <SERVERNAME>:<PORT> <SERVERNAME>:<PORT> et
c
cscript y.vbs server:123 a:0 0:a "nice try:4711" abc:abc abc:000
setup.exe server:123
setup.exe a:0
Bingo: 0:a
Bingo: nice try:4711
Bingo: abc:abc
setup.exe abc:000
0.2版:
使用斯普利特(OneAndOnlyArg ,「,」)來填寫RegExp:
Option Explicit
Dim args : Set args = WScript.Arguments.Unnamed
If args.Count <> 1 then
WScript.Echo "Error no arguments selected - usage: script.vbs <SERVERNAME>:<PORT>,<SERVERNAME>:<PORT>,<SERVERNAME>:<PORT> etc"
WScript.Quit
Else
Dim r : Set r = New RegExp
r.Pattern = "^\w+:\d+$"
Dim a, m
For Each a In Split(args(0), ",")
Set m = r.Execute(a)
If 1 <> m.Count Then
WScript.Echo "Bingo:", a
Else
WScript.Echo "setup.exe", m(0).Value
End If
Next
End If
輸出:
cscript y.vbs server:123,a:0,0:a,abc:abc,abc:000
setup.exe server:123
setup.exe a:0
Bingo: 0:a
Bingo: abc:abc
setup.exe abc:000
注意,空格將打破這種做法。
這真的很好...不幸的是,我用的setup.exe文件已經得到了有,我剛剛意識到不能有them..so之間的空間,它必須是:,: .....有沒有這樣做的機會? –
lara400
2015-04-01 10:42:33