Hi, good morning.
I'm trying to find a best way(with the best performance) to parse a Fix Protocol message.
Then I made some functions that return a value if I give a Fix Message and a Fix field. They work pretty well but I don't know if is the best way to do this.
See below:
best regards,
bruno
I'm trying to find a best way(with the best performance) to parse a Fix Protocol message.
Then I made some functions that return a value if I give a Fix Message and a Fix field. They work pretty well but I don't know if is the best way to do this.
See below:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FixField
{
class Program
{
private const char cEql = (char)61;
private const char cFixSep = (char)1;
private const string cFixMsg = @"8=FIX.4.29=27735=834=2489149=ABCD52=20100415-16:01:06.98256=FIX0999991=222222226=011=00500002000000097814=017=0101069762390120=031=032=037=2010041500578358587538=100039=040=241=00500002000000097744=000026.73054=255=IBM59=060=20100415-16:01:07150=0151=00000000100010=148";
static void Main(string[] args)
{
Console.WriteLine(FixField(cFixMsg,"9"));
Console.WriteLine(FixField2(cFixMsg, "9"));
}
static string FixField(string strFixMsg, string strField)
{
int intPos;
int intFieldLen;
int intEnd;
string strValue;
intFieldLen = strField.Length + 2;
intPos = strFixMsg.IndexOf(cFixSep + strField + cEql);
intEnd = strFixMsg.IndexOf(cFixSep, intPos + 1);
if (intPos == -1)
{
strValue = strFixMsg.Substring(2, intEnd - 2);
}
else
{
strValue = strFixMsg.Substring(intPos + intFieldLen, intEnd - intPos - intFieldLen);
}
return strValue;
}
static string FixField2(string strFixMsg, string strField)
{
string[] strValue = strFixMsg.Split(new char[] { cFixSep, cEql });
int i;
for (i = 0; strValue[I] != strField; i++)[/I]
{ }
return strValue[i + 1];
}
}
}
bruno