Sponsored By

Sign in to follow this  
iccaros

C# Help With Arguments

Recommended Posts

I know how to take strait arguments into C# but I am writing a console application that I would like to add agrumnets like -f or -F and a space then the agrgument

so it would look like a good unix command :)

example

command mydile.txt -p C:\user\username -l

my thought is to treat the flag as an argument then read the next one for the value ..

but I am not sure if there is a better way, as I can see this getting complex.. depending on how much the tool can do..

Share this post


Link to post
Share on other sites

That's pretty much how it's done on Unix. Iterate through the argument vector, when you find a flag that takes an argument at argv[n], grab the argument from argv[n+1] and bump n for the next pass. If you want a general solution, look at Unix's getopt(3) for inspiration.

(On the off chance that you're using GTK#, you might check if it includes GLib's GOption command-line parser.)

Share this post


Link to post
Share on other sites

thanks..

getops is a good example..

now back to work :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this