Reading arguments

C

csharpula csharp

Hello,
I am reading a line of arguments from command line,here is an example of
such line:

convert -d 01/01/07 -n New File 3 -p C:\MyDocuments

What is the best way to read it if for example New File 3 (which can
include spaces) is a file name that i need to store in string variable?

Thank y!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well you will have it interpreted as two parameters, if you want iut to be
interpreted as one you will need to surround it with quotes.

Alternately you may try to combine them in y our code.


The first is the best way IMO
 
C

csharpula csharp

Should I do it with a while look until i reach "-d" or -p" or end of the
line and append the parts of file name each time?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well that is definetely an option, but as I said before you would have to
implement the logic in your code.
 
B

Ben Voigt

csharpula csharp said:
Should I do it with a while look until i reach "-d" or -p" or end of the
line and append the parts of file name each time?

You may run into some problems not knowing how many spaces/tabs/whatever
were between the parts. Every utility I've ever written or used requires
quotes around filenames with spaces.
 
T

Tim Van Wassenhove

csharpula csharp schreef:
Hello,
I am reading a line of arguments from command line,here is an example of
such line:

convert -d 01/01/07 -n New File 3 -p C:\MyDocuments

What is the best way to read it if for example New File 3 (which can
include spaces) is a file name that i need to store in string variable?

I'd search for a 'getopt' library for .net. (eg:
http://www.stillhq.com/getopt/)

Btw, that would be -p "C:\\MyDocuments"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top