Reading arguments

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
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!
 
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
 
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?
 
Hi,

Well that is definetely an option, but as I said before you would have to
implement the logic in your code.
 
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.
 
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"
 
Back
Top