gpt4 book ai didi

node.js - 如何使用 Node-Express 计算 CSV 文件的行数

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:56 25 4
gpt4 key购买 nike

我需要计算 CSV 文件的行数。如果文件为空,我想将列名称写入第一行,然后是我需要记录的信息。

有什么建议吗?

最佳答案

var i;
var count = 0;
require('fs').createReadStream(process.argv[2])
.on('data', function(chunk) {
for (i=0; i < chunk.length; ++i)
if (chunk[i] == 10) count++;
})
.on('end', function() {
console.log(count);
});

这是 Node.js: Count the number of lines in a file 的重复项,请先学会用 google 搜索您的问题。

关于node.js - 如何使用 Node-Express 计算 CSV 文件的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24795156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com