Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(line: string) {
- const parts: string[] = [];
- const commaIndexes = [];
- let
- isOpen = false,
- lastIndex = 0;
- for (let i = 0; i < line.length; i++) {
- const char = line[i];
- if (char === "\"")
- isOpen = !isOpen;
- if (i === line.length - 1)
- parts.push(line.substr(lastIndex + 1));
- else
- if (char === "," && !isOpen) {
- parts.push(line.substring(lastIndex === 0 ? lastIndex : lastIndex + 1, i));
- lastIndex = i;
- }
- }
- return parts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement