Initially, I thought your data was fixed format, and that
string.Substring
would do it fairly easily. But a closer inspection shows it is already delimited: each field ends with CTRL-A.
You can just use
string.Split
to break the log line into it's component parts:
string[] parts = logEntry.Split('\x01');
Then, all you have to do is examine each part in turn, and determine from the bit to the left of the "=" if you want to keep it or not:
string logEntry = "8=FIX.4.39=6135=534=149=IDE50=FX52=20101219-18:05:01.52256=SAXOQUOTE10=171";
string[] parts = logEntry.Split('\x01');
StringBuilder sb = new StringBuilder(logEntry.Length);
string prefix = "";
foreach (string part in parts)
{
string[] breakdown = part.Split('=');
switch (breakdown[0])
{
case "9":
case "52":
sb.Append(prefix + part);
prefix = ",";
break;
}
}