C# Split strings between quotes

Viewed 70

In my Resource.resx file I have a field where I put a sequence of strings like:

"string1" "string two" "this is the string 3"

My goal is to obtain a sequence of strings.

What I did until now is the following:

private static string[] mystrings = Resource.str.Split(null);

but this just split the strings based on the space character. For the second and third strings this is a problem, so it is better to parse strings between " ".

Is there a way to do this?

1 Answers

You could use string.Trim to remove the leading/ending quotes and then string.Split and pass " " as the parameter to split the strings.

private static string[] mystrings = Resource.str.Trim('"').Split("\" \"", StringSplitOptions.None);

Example Fiddle

Related