-1

I have row which is coming from csv file like

"abc@example.com","seattle,US","9999 00000"

Expected Output:

abc@example.com
seattle,US
9999 00000

Actual output when I do string.Split(','):

"abc@example.com"
"seattle
US"
"9999 00000"
Tim Schmelter
  • 429,027
  • 67
  • 649
  • 891

1 Answers1

0

If you use " character to qualify a column, you can split by ","

string input = "\"abc@example.com\",\"seattle,US\",\"9999 00000\"";

string[] result = input.Trim('"').Split(new string[] { "\",\"" }, StringSplitOptions.None);
fubo
  • 42,334
  • 17
  • 98
  • 130
  • Haven't downvoted. But this is not a very good approach. The delimiter is clearly a comma not the quotes. Your workaround works in this case though – Tim Schmelter Sep 16 '16 at 10:39
  • @TimSchmelter but the quotes are even existing if there are no commas within their content – fubo Sep 16 '16 at 10:42
  • 1
    If every field in every line is surrounded by quotes, the splitting on "," seems fine to me. What's wrong with this answer? – Michael Gorsich Sep 16 '16 at 10:49