Parsing

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello I have the following line I need to read inside the command line:

executable -dir directory -type type1 -file file name

I want to read this line and to parse it inside variables,
how can i parse the file name if it can consist of couple of words with
spaces such as "file num 22"?

Can I avoid the following while?

while (++i<args.Length && !(args.Contains("-dir")) &&
!(args.Contains("-type")))
{
Name.Insert(Name.Length, args)
}

}
 
Hi,

I want to read this line and to parse it inside variables,
how can i parse the file name if it can consist of couple of words with
spaces such as "file num 22"?

Can I avoid the following while?

You have no way to avoid that, it will be parsed as different arguments by
the windows shell. and frankly how do u expect that the shell to know that
it's only one parameter?

You have two options:
1- enclose the parameter in quote, this is the regular way of doing it and
will work always
2- put the multi-word parameter at the end. and simply contact all the
values in your code
 
Back
Top