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,423
  • 4
  • 35
  • 62

1 Answers1

1

Try like this:

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

REGEX DEMO

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331