Using
Regular Expressions[
^] is one way to solve the problem.
Note that this code will only work the positions in the message are static.
Regex rx = new Regex(@"^(?<field1>[0-9A-F]{14})(?<field2>[0-9A-F]{22})(?<field3>[0-9A-F]{6})(?<field4>[0-9A-F]{12})(?<field7>[0-9A-F]{10})(?<field11>[0-9A-F]{6})(?<field12>[0-9A-F]{2})(?<field44>[0-9A-Z]{6})(?<field45>[0-9A-F]{3})(?<field105>[0-9A-Z ]+)$", RegexOptions.IgnoreCase);
(I put in some dummy fields to match the pattern)
string input = "0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890";
Match m = rx.Match(input);
if (m.Success)
{
string field3 = m.Groups["field3"].Value;
string field4 = m.Groups["field4"].Value;
}
[Update]
If the string is dynamic, but you know the position and length of the the parts you want, you can use
String.SubString
to do the extraction.
string input = "0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890";
int pos3 = 36;
int length3 = 6;
string field3 = input.Substring(pos3, length3);
int pos4 = pos3 + length3;
int length4 = 12;
string field4 = input.Substring(pos4, length4);