CSV字段中报价前的空格 [英] Space Before Quote in CSV Field

查看:120
本文介绍了CSV字段中报价前的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从CSV规范( RFC 4180 )中,Spaces are considered part of a field and should not be ignored.显然,如果该字段包含双引号,则应在引号内保留空格.

From the CSV spec (RFC 4180), Spaces are considered part of a field and should not be ignored. Obviously if the field contains double quotes it should retain the spaces inside the quotes.

我的问题是,双引号之外的空格怎么办?我看到这种情况的唯一方法是,如果生成CSV的工具没有正确执行此操作.

My question is, what about spaces outside of the double quotes? The only way I can see this happening is if the tool that generated the CSV didn't do it properly.

示例:one, "two" ,three

是否应在两个"之前和之后添加空格?

Should the space before and after "two" be included?

推荐答案

该单元格无效-为该行正确编码应该是:

That cell is invalid - to properly code that row it should be:

one," ""two"" ",three

双引号也必须转义(作为双双引号),因为它们被用作转义序列.如果您不想保留two周围的引号,从技术上讲,该行有两件事无效-(1)引号之前和之后的空格,以及(2)单元格周围有引号但没有任何内容的事实逃脱. CSV要求,如果单元格内容中包含逗号或引号,则该单元格周围只能有引号.

Double quotes must also be escaped (as double-double quote) since they are used as the escape sequence. If you don't want to preserve the quotes around two, technically there are two things invalid about the row - (1) the spaces before and after the quotes and (2) the fact that there are quotes around the cell but nothing to be escaped. CSV demands that there can only be quotes around the cell if there are commas or quotes inside the content of the cell.

如果我在您的情况下,我会宽大处理.

If I were in your case, I would err on the side of leniency.

这篇关于CSV字段中报价前的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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