A spreadsheet import screen previews uploaded CSV files row by row. Commas separate fields, but a field can be wrapped in double quotes so it may contain commas.
Write splitCsvRow(line) that returns the fields of one row. Rules:
" starts a quoted field only when it is the first character of a field. Inside a quoted field, "" stands for one " character, and a single " ends the quoting., is part of the field.Input: line = "name,\"Lima, Ana\",42" Output: ["name","Lima, Ana","42"]
The comma inside the quotes is part of the field.
Input: line = "say,\"He said \"\"hi\"\"\"" Output: ["say","He said \"hi\""]
Two quote characters inside quotes become one.
0 <= line.length <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #629 Split a CSV Row. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.