rutledgj
asked on
command line arguments in vb
dumb and simple question. I've created a console app and want to read in command line arguements. Main looks like this:
Dim s() As String = System.Environment.GetComm andLineArg s()
For i As Integer = 1 To UBound(s)
Console.WriteLine(s(i) & vbCrLf)
Next
Console.ReadLine()
in properties/debugger I'm passing in this:
"hello","world","you","are ","cruel"
when I run it s(1) contains the entire list of words. I expected each word to be in its own array position.
Can someone tell me what I'm doing wrong here?
Dim s() As String = System.Environment.GetComm
For i As Integer = 1 To UBound(s)
Console.WriteLine(s(i) & vbCrLf)
Next
Console.ReadLine()
in properties/debugger I'm passing in this:
"hello","world","you","are
when I run it s(1) contains the entire list of words. I expected each word to be in its own array position.
Can someone tell me what I'm doing wrong here?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Oh sorry I misread you.
The reason why you are seeing the command line arguments all in one shot is because command line arguments are tokenized by *whitespace*, not by commas.
So when you put in the arguments
"hello","world","you","are ","cruel"
There is no whitespace in that line, so it is considered to only be one argument. This is the behavior for all applications in Windows. If you wanted to accept command line arguments in that format you'd ned to parse it by comma yourself.
You probably meant to do this:
"hello" "world" "you" "are" "cruel"
The reason why you are seeing the command line arguments all in one shot is because command line arguments are tokenized by *whitespace*, not by commas.
So when you put in the arguments
"hello","world","you","are
There is no whitespace in that line, so it is considered to only be one argument. This is the behavior for all applications in Windows. If you wanted to accept command line arguments in that format you'd ned to parse it by comma yourself.
You probably meant to do this:
"hello" "world" "you" "are" "cruel"
http://msdn.microsoft.com/en-us/library/z2d603cy(v=vs.90).aspx