// 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.Linq; using System.Text.RegularExpressions; namespace E { public class Program { public static void Main(string[] args) { string line = "Tekst1, Tekst2, \"Tekst3, AndenTekst\",Tekst4, Tekst5"; char csvdelimiter = ','; Console.WriteLine(line); foreach(string part in Regex.Replace(line, "(\"[^\"]*)(,)([^\"]*\")", "$1#COMMA#$3").Split(csvdelimiter).Select(s => s.Replace("#COMMA#", ",").Trim())) { Console.WriteLine(part); } } } }