This commit is contained in:
Philippe Torrel
2026-10-01 10:37:23 +02:00
parent 58bdd6018f
commit 02b3745b88
8 changed files with 197 additions and 9 deletions
@@ -8,6 +8,28 @@ const quotedCSV = '"very big, soft computer mouse","the cutest peripheral ever",
const mixedCSV = '"very big, soft computer mouse","the cutest peripheral ever",10,39.90';
const parseCSVRecord = (record) => {
const fields = [];
let field = '';
let inQuotes = false;
for (const character of record) {
if (character === '"') {
inQuotes = !inQuotes;
} else if (character === ',' && !inQuotes) {
fields.push(field);
field = '';
} else {
field += character;
}
}
fields.push(field);
return fields;
};
console.log(parseCSVRecord(quotedCSV));
console.log(parseCSVRecord(mixedCSV));
/*
Übung 25: CSV-Datensätze mit Anführungszeichen
Bisher haben wir die Felder in einem CSV-Datensatz einfach mit der Anweisung: