加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式(C#)对于RFC 4180的CSV

发布时间:2020-12-14 06:00:30 所属栏目:百科 来源:网络整理
导读:到 specification RFC 4180需要通用CSV解析器. 有csv文件,包含规范的所有问题: Excel打开文件,因为它在规范中编写: 任何人都在使用正则表达式进行解析吗? CSV文件 “a b c”,”x y z”,357 test;test,xxx;xxx,152 “test2,test2″,”xxx2,xxx2”,123 “te
到 specification RFC 4180需要通用CSV解析器.
有csv文件,包含规范的所有问题:

Excel打开文件,因为它在规范中编写:

任何人都在使用正则表达式进行解析吗?

CSV文件

“a
b
c”,”x
y
z”,357
test;test,xxx;xxx,152
“test2,test2″,”xxx2,xxx2”,123
“test3″”test3″,”xxx3″”xxx3”,987
,qwe,13
asd,123,
,123
123,
123,123

预期成绩

解决方法

我会说,忘掉正则表达式. CSV可以通过TextFieldParser类轻松解析.要做到这一点,你需要做到

using Microsoft.VisualBasic.FileIO;

然后你可以使用它:

using (TextFieldParser parser = new TextFieldParser(Stream))
  {
    parser.TextFieldType = FieldType.Delimited;
    parser.SetDelimiters(",");

    while (!parser.EndOfData)
    {
      string[] fields = parser.ReadFields();
      foreach (string field in fields)
      {
         // Do your stuff here ...
      }
    }
  }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读