重複の可能性:
CSVデータを解析するためのJavascriptコード
私はこの文字列を持っています:
"display, Name" <test@test.com>, display" Name <test@test.com>, test@test.com
この文字列を配列に分割したい
array[0] = "\"display, Name\" <test@test.com>"
array[1] = "display\" Name <test@test.com>"
array[2] = "test@test.com"
これが私のコードです:
var comma = inQuotes = false;
for(var i=0;i<str.length;i++) {
if (str[i] == '"') inQuotes = !inQuotes;
comma = (str[i] == "," && !inQuotes) ? true : false;
item += (!comma) ? str[i] : "";
if(comma || i == str.length-1) {
items.push(item);
item = "";
}
}
私の問題は、文字列にクローザーがない二重引用符が1つある場合です
私は助けに感謝します...