title: String parsing techniques
body: <p>I am trying to find a good way to parse a message string into an object. 
  The string is of fixed length and described below.</p>
  
  <p><a href="https://i.stack.imgur.com/LscNN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LscNN.png" alt="Snippet of string spec"></a></p>
  
  <ul>
  <li>protocol = int(2) </li>
  <li>message type = string(1) </li>
  <li>measurement = string(4)</li>
  <li>etc</li>
  </ul>
  
  <p>Doing a simple <code>String.Split</code> will work, but I think may be a bit cumbersome when you start to get towards the end of the string. e.g.:</p>
  
  <pre><code>var field1 = s.SubString(0,2);
  var field2 = s.SubString(2,4);
  ....
  var field99 = s.SubString(88,4); // difficult magic numbers
  </code></pre>
  
  <p>I considered using a Regex and thought that maybe even more confusing. </p>
  
  <p>I was trying to think of an elegant solution, where I could create a Parser which was passed a 'config' that would detail how to parse the string. </p>
  
  <p>Something like...</p>
  
  <pre><code> MyConfig config = new MyConfig()
   config.Add("Protocol",    Length=2, typeof(int));
   config.Add("MessageType", Length=1, typeof(char));
  
  
   Parser p = new Parser(config);
   var parserResult = p.Parse(message);
  </code></pre>
  
  <p>...but I'm going around in circles at the minute and not getting anywhere. Any pointers would be a great help.  </p>