BestTechie Forums: C# Help With Arguments - BestTechie Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

C# Help With Arguments


#1 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 04 April 2008 - 11:01 AM

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

#2 User is offline   jcl 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1304
  • Joined: 30-August 04
  • Location:The Internet
  • Operating System:Arch

Posted 04 April 2008 - 07:11 PM

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

#3 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 05 April 2008 - 06:45 PM

thanks..
getops is a good example..

now back to work :)

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users