По мотивам ответа
mefutu
Примерное решение на конечном автомате:
using System;
using System.Text;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
Console.WriteLine(string.Join("|", Parse("Мама,\"мыла, блин\", раму,\"мама, мыла \"\"раму\"\"\",конец")));
}
public enum StateEnum{Start, StartQuot, Inline, InlineQuot}
public static IEnumerable<string> Parse(string str)
{
var state = StateEnum.Start;
var sb = new StringBuilder();
foreach(var ch in str)
{
switch(ch)
{
case '"':
switch(state)
{
case StateEnum.Start:
state = StateEnum.StartQuot;
continue;
case StateEnum.StartQuot:
case StateEnum.InlineQuot:
state = StateEnum.Inline;
sb.Append('"');
continue;
case StateEnum.Inline:
state = StateEnum.InlineQuot;
continue;
}
break;
case ',':
switch(state)
{
case StateEnum.Start:
case StateEnum.InlineQuot:
yield return sb.ToString();
sb.Clear();
state = StateEnum.Start;
continue;
case StateEnum.StartQuot:
case StateEnum.Inline:
sb.Append(',');
state = StateEnum.Inline;
continue;
}
goto default;
default:
sb.Append(ch);
break;
}
}
yield return sb.ToString();
}
}