// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Text; namespace E { public class Program { public static List Parse(String s, char delim, char quote) { List res = new List(); StringBuilder sb = new StringBuilder(); bool inquote = false; int ix = 0; while(ix < s.Length) { if(s[ix] == delim) { if(inquote) { sb.Append(s[ix]); } else { res.Add(sb.ToString()); sb = new StringBuilder(); } } else if(s[ix] == quote) { if(ix + 1 < s.Length && s[ix+1] == quote) { sb.Append(s[ix]); ix++; } else { inquote = !inquote; } } else { sb.Append(s[ix]); } ix++; } res.Add(sb.ToString()); return res; } public static void Main(string[] args) { List lst = Parse("123,#ABC#,#DE,FG#,#HI##JK#", ',', '#'); foreach(string s in lst) { Console.WriteLine(s); } } } }