command line arguments in vb

rutledgj
rutledgj used Ask the Experts™
on
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.GetCommandLineArgs()

        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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try using the My.Application.CommandLineArgs property instead, it is a collection of arguments tokenized by whitespace like you are expecting.

http://msdn.microsoft.com/en-us/library/z2d603cy(v=vs.90).aspx
The delimiter is a space.

Hello world you are cruel has 5

or "hello" "world" "you are cruel" has 3
The first is always the name of the program.
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"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial