こんにちは私はJavaScriptでCSVファイルを解析する際に問題があります。このCSVを解析するためにCSV JavaScriptのスライス文字列
<code>
date, hours, text
2004-05-04,05:22, Sample text, with coma
2005-05-04,05:22:00, Another Sample text, with coma
2006-05-04,05:22, Third Sample text, with coma
</code>
以下の構造CSV私は、私は、テキスト内のコンマているときに問題が、ある
<code>
$.ajax({
type: "GET",
url: "data.csv",
dataType: "text",
success: function(data) {processData(data);}
});
function processData(csv) {
var allTextLines = csv.split(/\r\n|\n/);
//console.log(allTextLines);
var lines = [];
while (allTextLines.length) {
//console.log(allTextLines);
lines.push(allTextLines.shift().split(","));
}
console.log(lines);
}
</code>
以下のコードを使用して、私はこの
<code>
lines[0]=['2004-05-04']['05:22'][Sample text][with comma];
</code>
ような配列を持っている私の質問は、これをこのような配列に変換する方法:
<code>
lines[0]=['2004-05-04']['05:22'][Sample text, with coma];
</code>
ありがとうございました!
の可能性のある重複した[どのようにデータにカンマが含まれているJavaScriptを使用してCSV文字列を、解析することができますか?](https://stackoverflow.com/questions/8493195/how-can- i-parse-a-csv-string-javascript-with-comma-in-data) – str
あなたのCSVは一貫して3列しか持っていませんか? –
はい私は3列を持っていますが、テキスト列にはもっと昏睡状態になることがあります – breakbit