Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the seperator for parameters from a space to a ¦ ?

Status
Not open for further replies.

ije

MIS
Jun 10, 2002
38
0
0
AU
I have a program that uses 2 parameters. I start the program at a command line like "script.vbs value1 value2"

In the script I use the following syntaxt to extract the parameters:
val1 = cstr(wscript.arguments(0))
val2 = cstr(wscript.arguments(1))

However, my parameters are now containing spaces, and I need to use another seperator, such as a |.

Can someone share a method of using a | as a seperator between parameters, instead of the standard space?

Thanks in advance
ije
 
Try something like this:
Code:
myArgsArray=Split(WScript.Arguments(0),"|")
val1=CStr(myArgsArray(0)
val2=CStr(myArgsArray(1)
Obviously this code must be made more robust with .Count and UBound checkings.

Hope This Help
PH.
 
The usual way this is handled would be:

C:\scripts\x.vbs
Code:
wscript.echo wscript.arguments(0)
wscript.echo wscript.arguments(1)
Running the script:
Code:
C:\scripts>cscript x.vbs billy "joe bob"

billy
joe bob

C:\scripts>
If quoting your arguments isn't feasible, you'll have to iterate the Arguments collection concatenating the bits you find all together putting spaces back between the parts. Then you could do a Split( ) using a "|" as the delimiter.
 
The best answer, as indicated above, is to use quotes around the arguments that have spaces in them.

The quotes are removed automatically from the arguments by wscript so there's no extra work involved.

In any case, assuming the command is being issued from the command line, I think you'd have to use a character other than | as that's the 'pipe' operator and the command processor will attempt to execute everything up to the | and pass the output to whatever is after the | which will almost certainly fail.

Other characters you can't use include < > ( ) ^ & as they are all conditional processing symbols in the command line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top