I am using .NET\'s String.Split method to break up a string using commas, but I want to ignore strings enclosed in double quotes for the string. I have read that a
For
I found below is the easiest way, we can do it
string fruits = "Fruit,10,"Bananas, Oranges, Grapes"";
string[] fruitsArr = Regex.Split(fruits, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
Output:
fruitsArr[0] = "Fruit"
fruitsArr[1] = "10"
fruitsArr[2] = "\"Bananas, Oranges, Grapes\""
If you need pure string data so you can do it something like,
fruitsArr[2].Replace("\"", "")