【发布时间】:2013-08-02 04:57:19
【问题描述】:
我的 csv 数据看起来像这样
1,2,"hi,how ar you?",abc
3,5,a,b,c
expected output should be
4
5
【问题讨论】:
-
这里是你应该找到的:stackoverflow.com/questions/2952805/…
标签: javascript csv row
我的 csv 数据看起来像这样
1,2,"hi,how ar you?",abc
3,5,a,b,c
expected output should be
4
5
【问题讨论】:
标签: javascript csv row
'1,2,"hi,how ar you?",abc'.match(/"[^"]*"|[^,]+/g).length
4
'3,5,a,b,c'.match(/"[^"]*"|[^,]+/g).length
5
【讨论】:
csv_file_content.split("\n")
试试这个源自另一个帖子的方法:
var csvLines = '1,2,"how ar you?",abc' + "\n" + '1,4,"fine",6,7';
var splitByChars = ',';
var totalCount = 0;
var linesArray = csvLines.split("\n");
var lineCount = 0;
while (lineCount < linesArray.length) {
totalCount += StringCount(csvLines, splitByChars);
lineCount++;
}
alert(totalCount);
function StringCount(stringToSplit, splitBy) {
var words = stringToSplit.split(splitBy);
return words.length;
}
【讨论】:
"hi,how ar you?" 视为 2 列。