Search code examples
c#stringcommand-line-argumentsarrays

Turn string into string array for command-line arguments


I have string with the following format:

"arg1" "arg2" "arg3" ... "argx"

I am going to use this string as the string[] for my program's command-line arguments. How can I turn this string into a string array?


Solution

  • Use the String.Split method to split the string on the original string.

    if you need to remove the Quotation marks as well you could either loop through the resulting array and getting the substrings without the quotation marks

    Alternatively you could use the Regex.Split to do it in one go.