Parse multiple named command line parameters
- by scholzr
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?