using System.Collections.Generic;
public static void Main()
string s = $"custattr3=esk_koorder|queue|321-123-123|;td.entityRef=321312-31-23-21-;centreftype=contact;";
string[] subs = s.Split('|');
var test = ParseToDictionary(s, ';', true);
foreach (KeyValuePair<string, string> attr in test)
if (attr.Key.ToLower().StartsWith("custattr"))
var split = attr.Value.Split('|');
for (var i = 0; i < 3; i++)
Console.WriteLine(split[i]);
public static Dictionary<string, string> ParseToDictionary(string buffer, char delim, bool decode = false, bool preDecode = false) {
Dictionary<string, string> tagDict = new Dictionary<string, string>();
buffer = DecodeString(buffer);
string[] nvpArray = buffer.Split(delim);
foreach (string nvp in nvpArray) {
int nvpDelimPos = nvp.IndexOf('=');
string str = nvp.Substring(nvpDelimPos + 1);
string decodedVal = DecodeString(str);
tagDict.Add(nvp.Substring(0, nvpDelimPos), decodedVal);
tagDict.Add(nvp.Substring(0, nvpDelimPos), nvp.Substring(nvpDelimPos + 1));
private static string DecodeString(string str)
return new StringBuilder(str.Replace("#23", "#").Replace("#3B", ";").Replace("#3D", "=").Replace("#0D", "\x0d").Replace("#0A", "\x0a").Replace("#0B", "\x0b")).ToString();