Split string by commas ignoring any punctuation marks (including ',') in quotation marks

前端 未结 6 1712
甜味超标
甜味超标 2021-01-22 06:10

How can I split string (from a textbox) by commas excluding those in double quotation marks (without getting rid of the quotation marks), along with other poss

6条回答
  •  北海茫月
    2021-01-22 06:27

    Try this:

    Regex str = new Regex("(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)", RegexOptions.Compiled);
    
    foreach (Match m in str.Matches(input))
    {
        Console.WriteLine(m.Value.TrimStart(','));
    }
    

    You may also try to look at FileHelpers

提交回复
热议问题