I am trying to split a string by spaces, except when the token is between quotation marks. However, the code I have written also splits the string on the .
character, which I do not want. Here is my code:
string txt = "PROGRAM \"My ETABS\" VERSION \"9.7.4\" MERGETOL 0.1";
string[] split = Regex.Matches(txt, "(\\w+|\".*?\")")
.Cast<Match>()
.Select(m => m.Value)
.Select(o => o.Replace("\"", ""))
.ToArray();
What I get:
PROGRAM
My ETABS
VERSION
9.7.4"
MERGETOL
0
1
What I need:
PROGRAM
My ETABS
VERSION
9.7.4"
MERGETOL
0.1
How can I modify this code to split the string by spaces, unless the token is between quotation marks, without splitting on the .
character?