public static string Scrub(string csvRecord, string prefix, char delimiter = ',')
if (string.IsNullOrEmpty(csvRecord) || string.IsNullOrEmpty(prefix))
int prefixIndex = csvRecord.IndexOf(prefix);
string left = csvRecord.Substring(0, prefixIndex).TrimEnd(' ', delimiter);
string right = csvRecord.Substring(prefixIndex);
int delimIndex = right.IndexOf(delimiter);
right = delimIndex == -1 ? string.Empty : right.Substring(delimIndex);
public static string Scrub(string csvRecord, string[] prefixes, char delimiter = ',')
if (prefixes != null && prefixes.Length > 0)
foreach (string prefix in prefixes)
csv = Scrub(csv, prefix, delimiter);
public static void Main(string[] args)
Console.WriteLine(Scrub("abc,def,123,hij", "12"));