I am making a personal terminal, it doesn't do a lot and doesn't really have a specific purpose, I'm mostly just bored. I have been banging my head against a wall for about a day now trying to do this manually before trying to research it.
When I did research it I found this and changed it a bit to apply to my code
var re = new Regex("(?<=\")[^\"]*(?=\")|[^\" ]+");
string[] NewTokens = re.Matches(fullstring).Cast<Match>().Select(m => m.Value).ToArray();
The fullstring
variable is all of my tokens clumped together (basically just the user input for a command), not seperated by spacing. Just the normal string before it is deconstructed into a string[]
of tokens.
I need this string to be seperated by spaces but ignore that when there are quotes. For example if I wanted to make a command that prints out a message into the console I would do:
print "Hello World!"
as my command.
The output I would like is:
[0] -> print
[1] -> Hello World!
The code example seems to work...but when I try to run a command that doesnt have quotes like:
(print being the command the help command looks for)
help print
The output is:
[0] -> helpprint
The tokens should be:
[0] -> help
[1] -> print
Please help. Normally I wouldn't ask for help, but I really can't find a fix for this online or by myself.