title: Read fixed width record from text file
body: <p>I've got a text file full of records where each field in each record is a fixed width.  My first approach would be to parse each record simply using string.Substring().  Is there a better way? </p>
  
  <p>For example, the format could be described as:</p>
  
  <pre><code>&lt;Field1(8)&gt;&lt;Field2(16)&gt;&lt;Field3(12)&gt;
  </code></pre>
  
  <p>And an example file with two records could look like:</p>
  
  <pre><code>SomeData0000000000123456SomeMoreData
  Data2   0000000000555555MoreData    
  </code></pre>
  
  <p>I just want to make sure I'm not overlooking a more elegant way than Substring().</p>
  
  <hr>
  
  <p><strong>Update:</strong>  I ultimately went with a regex like Killersponge suggested:</p>
  
  <pre><code>private readonly Regex reLot = new Regex(REGEX_LOT, RegexOptions.Compiled);
  const string REGEX_LOT = "^(?&lt;Field1&gt;.{6})" +
                          "(?&lt;Field2&gt;.{16})" +
                          "(?&lt;Field3&gt;.{12})";
  </code></pre>
  
  <p>I then use the following to access the fields:</p>
  
  <pre><code>Match match = reLot.Match(record);
  string field1 = match.Groups["Field1"].Value;
  </code></pre>