本文介绍了正则表达式(C#)对于RFC通过RFC 4180的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要通过提供的通用CSV解析器。
有一个csv文件,其中包含规范的所有问题:

Requires universal CSV parser by specification RFC 4180.There is the csv file, with all the problems of the specification:

Excel打开文件时,它是写在规范:

Excel opens the file as it is written in the specification:

任何人都可以正常工作正则表达式来解析它?

Anyone does work regex for parse it?

CSV文件

预期结果

推荐答案

我会说,忘了regex。 CSV可以通过TextFieldParser类轻松解析。为此,您需要使用Microsoft.VisualBasic.FileIO来

I would say, forget about regex. CSV can be parsed easily by TextFieldParser class. To do that, you need to be

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 ...
      }
    }
  }

这篇关于正则表达式(C#)对于RFC通过RFC 4180的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:24