Parse multiple named command line parameters
Posted
by
scholzr
on Stack Overflow
See other posts from Stack Overflow
or by scholzr
Published on 2012-11-19T22:47:47Z
Indexed on
2012/11/19
23:00 UTC
Read the original article
Hit count: 268
vb.net
|command-line
I need to add the ability to a program to accept multiple named parameters when opening the program via the command line. i.e.
program.exe /param1=value /param2=value
and then be able to utilize these parameters as variables in the program. I have found a couple of ways to accomplish pieces of this, but can't seem to figure out how to put it all together.
I have been able to pass one named parameter and recover it using the code below, and while I could duplicate it for every possible named parameter, I know that can't be the preffered way to do this.
Dim inputArgument As String = "/input="
Dim inputName As String = ""
For Each s As String In My.Application.CommandLineArgs
If s.ToLower.StartsWith(inputArgument) Then
inputName = s.Remove(0, inputArgument.Length)
End If
Next
Alternatively, I can get multiple unnamed parameters from the command line using
My.Application.CommandLineArgs
But this requires that the parameters all be passed in the same order/format each time. I need to be able to pass a random subset of parameters each time.
Ultimately, what I would like to be able to do, is separate each argument and value, and load it into a multidimentional array for later use. I know that I could find a way to do this by separating the string at the "=" and stripping the "/", but as I am somewhat new to this, I wanted to see if there was a "preffered" way for dealing with multiple named parameters?
© Stack Overflow or respective owner