Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get the last command line argument or argument without the delimiter

How to get the last command line argument or argument without the delimiter

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zxc89
    wrote on last edited by
    #1

    Hi.. I use C#.NET.. I pass 4 - 5 command line arguments to my appln. for eg: /c:class /d:define /o:outputfile Infile for the first 3 arguments i can find them based on delimiters("/c:" "/d:" "/o:") But how can i find the last argument(also it can be anywhere in the command line arguments ) One thing is sure the "InFile" argument will not have any delimiters. Plz provide me the code to do this..Plz Help!!!

    C 1 Reply Last reply
    0
    • Z zxc89

      Hi.. I use C#.NET.. I pass 4 - 5 command line arguments to my appln. for eg: /c:class /d:define /o:outputfile Infile for the first 3 arguments i can find them based on delimiters("/c:" "/d:" "/o:") But how can i find the last argument(also it can be anywhere in the command line arguments ) One thing is sure the "InFile" argument will not have any delimiters. Plz provide me the code to do this..Plz Help!!!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The space is always a delimiter, unless it's in quotes. So, you can build a regex to delimit based on spaces outside quotes.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      Z 1 Reply Last reply
      0
      • C Christian Graus

        The space is always a delimiter, unless it's in quotes. So, you can build a regex to delimit based on spaces outside quotes.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        Z Offline
        Z Offline
        zxc89
        wrote on last edited by
        #3

        I am not able to do with that..Is there any other possible way???

        C 1 Reply Last reply
        0
        • Z zxc89

          I am not able to do with that..Is there any other possible way???

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Why can't you ? There's no other way I can see, unless you're sure there will never be quotes, then the space is a delimiter. If you're unwilling to use a regex ( and if you don't know how, you should learn ), then you can always string mash your way to a solution, it's just nicer to do it properly.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          Z 1 Reply Last reply
          0
          • C Christian Graus

            Why can't you ? There's no other way I can see, unless you're sure there will never be quotes, then the space is a delimiter. If you're unwilling to use a regex ( and if you don't know how, you should learn ), then you can always string mash your way to a solution, it's just nicer to do it properly.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            Z Offline
            Z Offline
            zxc89
            wrote on last edited by
            #5

            it will definetly have quotes bcoz its the input file name i should pass.. So it will definetly have quotes..say eg: "d:\c plus\some.h"..so this string should always be specified in quotes..

            C 1 Reply Last reply
            0
            • Z zxc89

              it will definetly have quotes bcoz its the input file name i should pass.. So it will definetly have quotes..say eg: "d:\c plus\some.h"..so this string should always be specified in quotes..

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              OK, then your choices are regex or string mashing ( that is, counting spaces and quotes manually in code )

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups