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..

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.)

Link to post
Share on other sites

thanks..

getops is a good example..

now back to work :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...