-2

You are provided with the following CSV file content as a variable:

"Buchungstag";"Wertstellung (Valuta)";"Vorgang";"Buchungstext";"Umsatz in EUR";
"22.10.2020";"22.10.2020";"Übertrag / Überweisung";"Auftraggeber: XY Buchungstext: KD 1 RE 3000 Ref. 123/456";"18,80";
"19.10.2020";"19.10.2020";"Übertrag / Überweisung";"Auftraggeber: AB Buchungstext: KD 1 RE 3000 Ref. 123/457";"160,00";

The goal is to parse this CSV file content, but when I declare the variable, it takes only the first value because the semicolon is the divider and it gives me a syntax error for all the other content of the CSV.

var csv= "Buchungstag";"Wertstellung (Valuta)";"Vorgang";"Buchungstext";"Umsatz in EUR"; "22.10.2020";"22.10.2020";"Übertrag / Überweisung";"Auftraggeber: XY Buchungstext: KD 1 RE 3000 Ref. 123/456";"18,80"; "19.10.2020";"19.10.2020";"Übertrag / Überweisung";"Auftraggeber: AB Buchungstext: KD 1 RE 3000 Ref. 123/457";"160,00";

error

  • 1
    Please share the code you have tried so far – Dominik Nov 03 '20 at 21:06
  • So are you not reading in the file with fetch or XMLHttpRequest or file? If you are not importing it, the issue is that is supposes to be one string. It is missing quotes around it. – epascarello Nov 03 '20 at 21:06
  • Welcome to StackOverflow! Can you share what you've tried so far? StackOverflow isn't a free code-writing service, and expects you to try to solve your own problem first. Please update your question to show what you have already tried, showing the specific problem you are facing in a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve). For further information, please see [how to ask good questions](http://stackoverflow.com/help/how-to-ask), and take the [tour of the site](http://stackoverflow.com/tour). – coagmano Nov 03 '20 at 21:06

1 Answers1

0

You can put the entire value between single quotes:

const csv = '"Buchungstag";"Wertstellung (Valuta)";"Vorgang";"Buchungstext";"Umsatz in EUR";\n
"22.10.2020";"22.10.2020";"Übertrag / Überweisung";"Auftraggeber: XY Buchungstext: KD 1 RE 3000 Ref. 123/456";"18,80";\n
"19.10.2020";"19.10.2020";"Übertrag / Überweisung";"Auftraggeber: AB Buchungstext: KD 1 RE 3000 Ref. 123/457";"160,00";\n';

(Notice the \ns for the line breaks)

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Or just use [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)? I would assume it's unlikely that they can change the dataset on each line. – Dominik Nov 03 '20 at 21:08
  • great it worked with your idea but I had to erase the break lines from the string with the keyboard and then add the \n. Here is the code:var csv = '"Buchungstag";"Wertstellung (Valuta)";"Vorgang";"Buchungstext";"Umsatz in EUR";\n"22.10.2020";"22.10.2020";"Übertrag / Überweisung";"Auftraggeber: XY Buchungstext: KD 1 RE 3000 Ref. 123/456";"18,80";\n"19.10.2020";"19.10.2020";"Übertrag / Überweisung";"Auftraggeber: AB Buchungstext: KD 1 RE 3000 Ref. 123/457";"160,00";\n'; console.log('csv',csv); – Fernando Elias Nov 04 '20 at 00:17