在项目中,需要导出查询结果集,但是每天记录的其中一项描述内容可以包含逗号,一开始的解决方案是直接把内容的逗号替换为点。很显然改动了用户体验,客户可不允许这样做,没得办法直接到网上找夏解决方案。
Example
Year | Make | Model | Description | Price |
---|---|---|---|---|
1997 | Ford | E350 | ac, abs, moon | 3000.00 |
1999 | Chevy | Venture "Extended Edition" | 4900.00 | |
1999 | Chevy | Venture "Extended Edition, Very Large" | 5000.00 | |
1996 | Jeep | Grand Cherokee | MUST SELL! air, moon roof, loaded | 4799.00 |
The above table of data may be represented in CSV format as follows:
Year,Make,Model,Description,Price 1997,Ford,E350,"ac, abs, moon",3000.00 1999,Chevy,"Venture ""Extended Edition""","",4900.00 1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00 1996,Jeep,"Grand Cherokee","MUST SELL! air, moon roof, loaded",4799.00[注意]实际上你保存成CSV 格式,直接用记事本打开,就可以看清他里面保存的内容了。
提示:在下列 CSV 行中,一定要逗号和双引号紧挨着,中间不要有空隙,否则实效。
1997,Ford,E350,"ac, abs, moon",3000.00
[参考]http://en.wikipedia.org/wiki/Comma-separated_values