title: Split Text file with fixed width with different sizes
body: <p>I am stuck on a problem where I need to split a file with fixed width. Each field can be identified by its first character.</p>
  
  <p>The file contains multiple format for example, the first row's format is {1, 11, 12} while second row's format is {1, 10, 12}. Both are identified with the first character. </p>
  
  <pre><code>AFirstField SecondFields
  BBField    SecondFields
  </code></pre>
  
  <p>However, sometimes a row can come with less characters like below.</p>
  
  <pre><code>AFirstField S
  </code></pre>
  
  <p>What I have tried so far is using text parser getting the current line and check the first character to decide the format, but the application falls over because sometimes rows have less data on them, like the A example above.</p>
  
  <pre><code>string[] data;
  
      using (TextFieldParser myReader = new TextFieldParser(filePath))
      {
          myReader.TextFieldType = FieldType.FixedWidth;
  
          while (!myReader.EndOfData)
          {
              currentLine = myReader.ReadLine();
              recordType = currentLine[0].ToString();
  
              if (!recordType.Equals("H"))
              {
                  myReader.FieldWidths = returnLineFormat();
                  myReader.HasFieldsEnclosedInQuotes = true;
                 data = myReader.ReadFields();
  
  
  
                  //if (recordType.Equals("R"))
                  //{
                  //    ISD.Add(data);
                  //}
  
              }
  
          }
  
      }
  
  
  private int[] returnLineFormat()
  {
      int[] format = null;
  
      if ((recordType == "A"))
      {
          format = new int[] { 1, 11, 12};
      }
      else if ((recordType == "B"))
      {
          format = new int[] { 1, 10, 12};
      }
  
      return format;
  }
  </code></pre>
  
  <p>These are the errors I am getting cause of row having less stuff:
  Line 3 cannot be parsed using the current FieldWidths.</p>
  
  <p>Is there a way around this problem?</p>