gpt4 book ai didi

csv - 处理 CSV 文件中的逗号

转载 作者:行者123 更新时间:2023-12-03 03:55:30 24 4
gpt4 key购买 nike

我正在寻找有关如何处理由我们的客户创建并上传的 csv 文件的建议,该文件的值中可能包含逗号,例如公司名称。

我们正在研究的一些想法是:带引号的标识符(值“、”值“、”等)或使用 |而不是逗号。最大的问题是我们必须让它变得简单,否则客户不会这么做。

最佳答案

实际上有一个 CSV 格式的规范,RFC 4180以及如何处理逗号:

Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.

http://tools.ietf.org/html/rfc4180

因此,要获得值 foobar,baz,您可以这样做:

foo,"bar,baz"

需要考虑的另一个重要要求(也来自规范):

If double-quotes are used to enclose fields, then a double-quoteappearing inside a field must be escaped by preceding it withanother double quote. For example:

"aaa","b""bb","ccc"

关于csv - 处理 CSV 文件中的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/769621/

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