如何将带有逗号的双引号(“"”)数据插入一列,而将CSV文件插入到使用C#的数据表中? [英] How to insert double quote ("") data with comma into one column while CSV file to datatable using in C# ?

查看:88
本文介绍了如何将带有逗号的双引号(“"”)数据插入一列,而将CSV文件插入到使用C#的数据表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to insert double quote ("") data with comma into one column while  CSV file to datatable using in C# ?





我尝试过:





What I have tried:

How to insert double quote ("") data with comma into one column while  CSV file to datatable using in C# ?

推荐答案

CSV数据很原始,但它可以应付大多数的东西。如果你想在CSV数据的字段中使用逗号,换行符或双引号,则整个字段需要用双引号括起来:

CSV Data is pretty primitive, but it can cope with most things. If you want a comma, a newline or a double quote in a field in CSV data, teh whole field needs to be encased in double quotes:
123, Hello there, "A comma, in a field", 666



这给你四个字段:


Which gives you four fields:

123
Hello there
A comma, in a field
666

在双引号内你可以包含一个双引号,但是用第二个引用它:

Inside the double quotes you can include a double quote, but escaping it with a second one:

123, Hello there, "Some ""quoted text""", 666

这也给你四个字段:

Which also gives you four fields:

123
Hello there
Some "quoted text"
666

如果你想将它包含在C#字符串文字中,那么你还需要添加C#转义符:

If you want to include that in a C# string literal, then you need to add the C# escapes as well:

string csvData = "123, Hello there, \"Some \"\"quoted text\"\"\", 666";

或更糟:

Or worse:

string csvData = @"123, Hello there, ""Some """"quoted text"""""", 666";


这篇关于如何将带有逗号的双引号(“"”)数据插入一列,而将CSV文件插入到使用C#的数据表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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