0

I'm quite new to javascript and trying to learn by working on some scripts. I'm pulling data from a CSV as a string ( attachments[k].getDataAsString(); ) which pulls in test results with a combination of numbers and text. I've done this several times before but the issue this time is that this report uses commas as the separator for thousands which causes breaks at the thousands when being imported into a Google Sheet.

Here's an example of what is currently being pulled: "completed (Percent)

Day,Total,,,,,"48,303",100.00%,"41,429",100.00%,"9,302",100.00%,"3,948",100.00%
Day,"Nov 11, 2014",,,,,"7,050",14.60%,"6,428",15.52%,"1,646",17.70%,698,17.68%"

There is a combination of numbers between "" and some between commas when there is no thousands separator.

Is there a way to remove the comma for thousands separators and quotes across the string while keeping the remaining commas for the breaks?

Thanks!

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • could you provide an expected output for the above input? – Avinash Raj Nov 19 '14 at 04:05
  • 1
    There is number of ready to use javascript csv parsers available, no need to reinvent the wheel. – zerkms Nov 19 '14 at 04:09
  • thanks @zerkms ! I hadn't came upon any. I wasn't using the write term "parsers". I'm a newb. I ended up using this one: http://stackoverflow.com/questions/26854563/how-to-automatically-import-data-from-uploaded-csv-or-xls-file-into-google-sheet – Gobadia Nov 25 '14 at 15:22

1 Answers1

0

You can use a regex of the form

"([^,]*),([^,]*)"

replace it with $1$2

For example: http://regex101.com/r/sW6jE7/1

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52