Let's say I have a string array like so
string[] arr = new {"a", "b", "\"b", "c\"", "c"};
I want to collapse these array into an array like so, while stripping the quotes.
{"a", "b", "b c", "c"}
How do I achieve this with a single LINQ line?
Let's say I have a string array like so
string[] arr = new {"a", "b", "\"b", "c\"", "c"};
I want to collapse these array into an array like so, while stripping the quotes.
{"a", "b", "b c", "c"}
How do I achieve this with a single LINQ line?
From your example, I assume that you want to recombine your array into a string with space as separator, then split it again, but refrain from splitting quoted substrings. Adapting the regex from this answer, this could be your solution:
string[] arr = new [] { "a", "b", "\"b", "c\"", "c" };
var result = Regex
.Matches(string.Join(" ", arr), @"(?<match>[^\s""]+)|""(?<match>[^""]*)""")
.Cast<Match>()
.Select(m => m.Groups["match"].Value)
.ToList();