Search code examples
quotation-marks

splitting Strings into a String Array


I have a Spreadsheet as a .txt file and I need to split each row into an Array for further calculations each value is divided by a ",".

My Problem is some values have quotation marks and inside these quotation marks, they use commas. How can I separate the values without splitting the value inside the quotation marks?

Example row:

1000,117090058,117970084,"170,9 + 58","179,7 + 84","Flensburg Weiche, W 203 - Flensburg Grenze",Flensburg-Weiche - Flensb. Gr


Solution

  • This one liner should work:

    yourString.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")