如何获取CSV文件中的总行数

huangapple go评论75阅读模式
英文:

how to get total row num in csv file

问题

我会为你翻译以下内容:

我想先获取总行数,如果行数符合要求,就从文件开头解析,但我已经知道上面的代码示例会获取到行数,但光标会停留在文件末尾。如何处理这个问题?

reader := csv.NewReader(fs)
reader.ReadAll()

除了上述方法之外,如果有的话,还可以提供其他获取总行数的方法。

英文:

I would like to get total row num first, if num meets need, will parse file from beginning, but I have known above code sample will get number but cursor is at the end of file. how to handle it?

reader := csv.NewReader(fs)
reader.ReadAll()

except for above way, can also provide other ways to get total rows if have

答案1

得分: 1

很抱歉,由 csv 包 实现的 RFC 4180 并没有定义任何元数据来跟踪总行数。当然,有些应用程序可能会存储这样的元数据,但在这种情况下,您需要使用自定义解析器来读取它们。

英文:

Unfortunately, RFC 4180 which is implemented by csv package does not define any metadata which would keep track of total rows. Of course some applications may store such metadata but in such case you would need a custom parser for reading them.

huangapple
  • 本文由 发表于 2021年9月22日 18:31:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/69282510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定