有没有办法在CSV列中包含逗号而不破坏格式? [英] Is there a way to include commas in CSV columns without breaking the formatting?

查看:562
本文介绍了有没有办法在CSV列中包含逗号而不破坏格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含名称和数字的两列CSV。有些人的名字使用逗号,例如 Joe Blow,CFA。这个逗号断开了CSV格式,因为它被解释为一个新的列。

I've got a two column CSV with a name and a number. Some people's name use commas, for example Joe Blow, CFA. This comma breaks the CSV format, since it's interpreted as a new column.

我读过,最常见的处方似乎是用一个新值替换该字符,或替换分隔符(例如 this | that | other,)。

I've read up and the most common prescription seems to be replacing that character, or replacing the delimiter, with a new value (e.g. this|that|the, other).

我真的想保留逗号分隔符(我知道excel支持其他分隔符,但其他解释器可能不)。我也想保留逗号的名称,如 Joe Blow |

I'd really like to keep the comma separator (I know excel supports other delimiters but other interpreters may not). I'd also like to keep the comma in the name, as Joe Blow| CFA looks pretty silly.

有没有办法在CSV列中包含逗号而不破坏格式,例如通过转义?

Is there a way to include commas in CSV columns without breaking the formatting, for example by escaping them?

推荐答案

CSV格式的问题是没有一个规范,有几种接受的方法,没有办法区分哪些应该使用(用于生成/解释)。我在另一篇文章。基本上,它是为目标用户使用CSV生成/转义过程,并希望其他人不在乎。

The problem with the CSV format, is there's not one spec, there are several accepted methods, with no way of distinguishing which should be used (for generate/interpret). I discussed all the methods to escape characters (newlines in that case, but same basic premise) in another post. Basically it comes down to using a CSV generation/escaping process for the intended users, and hoping the rest don't mind.

参考规范文档

这篇关于有没有办法在CSV列中包含逗号而不破坏格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆