2

I've a string like this

 1,2,3,"a,b,c",4,"5,6"

I want split above string using .Split(',');

Expected:

  1. 1
  2. 2
  3. 3
  4. a,b,c
  5. 4
  6. 5,6

Actual: As usual, it is splitting 4 and 6 also. It is default behaviour. But any other ways where can i get ehat i am expecting?

Prasad Kanaparthi
  • 6,154
  • 3
  • 32
  • 60

1 Answers1

1

Try like this:

var result = Regex.Split(myString, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)\");

REGEX DEMO

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319