I'm fairly new and I couldn't get this to work properly.
I have this string
["string1","string2","string3","string4","string5","string6","string7","string8","string9","string10"]
And I want to get all values between the "
I think regex would be best to do the task.
Thanks for your help.
This will capture between the quotes:
(?<=")[\w]+(?!=")
An expanded example:
string s = "[\"string1\",\"string2\",\"string3\",\"string4\",\"string5\",\"string6\",\"string7\",\"string8\",\"string9\",\"string10\"]";
foreach (Match m in Regex.Matches(s, "(?<=\")[\\w]+(?!=\")")) {
Console.WriteLine(m.Value);
}
Since this looks like JSON, try using the JavaScriptSerializer class
string myString = "[\"string1\",\"string2\",\"string3\",\"string4\",\"string5\",\"string6\",\"string7\",\"string8\",\"string9\",\"string10\"]";
string[] strings = (new JavaScriptSerializer()).Deserialize<string[]>(myString);
foreach (string str in strings)
{
Console.WriteLine(str);
}
Kinda seems overkill though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With