Standard pattern for parsing command lines

  • Thread starter Thread starter John Paulsson
  • Start date Start date
J

John Paulsson

Is there a C# pattern or perhaps a .NET framework way of parsing a command
lines, supporting quoted filepaths etc?

(I'm not talking about the current applications command arguments. I've got
command strings that I need to parse into an array)
 
John Paulsson said:
Is there a C# pattern or perhaps a .NET framework way of parsing a command
lines, supporting quoted filepaths etc?

Unfortunatly I don't believe the framework defines any classes for parsing
such things, if that is what you mean.

You might be able to find 3rd party classes to do so, perhaps a getopt port
or the like.
 
Daniel O'Connell said:
Unfortunatly I don't believe the framework defines any classes for parsing
such things, if that is what you mean.

You might be able to find 3rd party classes to do so, perhaps a getopt
port or the like.

I assumed, and was almost sure there would be a class for such a common task
like parsing/splitting command lines some where in .net's class library,
perhaps under the IO.Path, Text namespace, whatever (been searching like mad
for an hour or so). Argh, oh well. back to "basic".
 
John Paulsson said:
I assumed, and was almost sure there would be a class for such a common
task like parsing/splitting command lines some where in .net's class
library, perhaps under the IO.Path, Text namespace, whatever (been
searching like mad for an hour or so). Argh, oh well. back to "basic".

Unfortunatly, there is nothing. It is a basic function, yes, but the Main
method retrieves the command line already parsed in whatever method the
operating system does, I assume that they designers felt they didn't need to
add support.
 
John said:
Is there a C# pattern or perhaps a .NET framework way of parsing a
command lines, supporting quoted filepaths etc?

(I'm not talking about the current applications command arguments.
I've got command strings that I need to parse into an array)

There's an ArgParser class shipped as part of the samples in the 1.1
Framework. Take a look at I:\Program Files\Microsoft Visual Studio
..NET\FrameworkSDK\Samples\Applications\WordCount\cs\ArgParser.cs

--
Arild

AnkhSVN - Subverting Visual Studio .NET: http://ankhsvn.tigris.org
Blog: http://ankhsvn.com/blog
IRC: irc://irc.freenode.net/ankhsvn

"Gentlemen, you can't fight in here! This is the war room!"
 
John

that is not a good use of the word "pattern" -- patterns are abstract
concepts - like a factory, a bridge, etc -- seems you are looking for real
code.

regards
roy fine
 
Back
Top