title: How to parse specific line in a text file in c#
body: <p>I need to parse a specific lines in a text file in which to begin by a specific words as in the following image :</p>
  
  <p><a href="https://i.stack.imgur.com/WYeML.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WYeML.png" alt="enter image description here"></a></p>
  
  <p>I need to parse the lines that begins by "Level" only and extract the value of "Row" and "Col" only. 
  Note that the text file will contain 6 groups of such data where each group starts by </p>
  
  <blockquote>
    <p>---------------- chromosome : # ------------------</p>
  </blockquote>
  
  <p>See the following sample :  <a href="https://www.dropbox.com/s/4qz9agm5e2yrhej/TreeParser.txt?dl=0" rel="nofollow noreferrer">Sample</a></p>
  
  <p>I need to save each group's row and columns in a separated list for each!!. 
  Is there any way to perform this ?</p>
  
  <p>I tried the following method : </p>
  
  <pre><code>public List&lt;int[,]&gt; getValuesFromTextFile(String filePath ) {
  
       IEnumerable&lt;string&gt; allLines = Enumerable.Empty&lt;string&gt;();
  
       List&lt;int[,]&gt; path = new List&lt;int[,]&gt;();
  
       int[,] item = new int[2,1];
  
      if (File.Exists(filePath))
  
          {
                      //Read all content of the files and store it to the list split with new line 
                      allLines = File.ReadLines(filePath);
          }
   
                      //all Level lines
                  IEnumerable&lt;string&gt; levelLines = allLines.Where(d =&gt; d.StartsWith("Level", StringComparison.CurrentCultureIgnoreCase));
   
                  foreach(string line in levelLines)
  
                  {
                       string[] values= line.Split(':');//either space or tab or others as your file contain seperator  
  
                       for(int i=1; i &lt;values.Length;i++)  {
  
                       string value = values[i];// skip index 0,it contains label, remaining are point data
  
                       if (i == 3) item[1,0] = Int32.Parse(value);
  
                       if (i == 5 &amp;&amp; item[1,0] != null ) { item[0,0] = Int32.Parse(value);
                            path.Add(item);
  
                            }
  
                   }
  
          }
  
  
  
                  return path;
  
          }
  </code></pre>
  
  <p>I got the following error at line( <code>if (i == 3) item[1,0] = Int32.Parse(value);</code> ) : </p>
  
  <blockquote>
    <p>Input string was not in a correct format.</p>
  </blockquote>
  
  <p>When I put a break point at this line I saw that the value of string "value" equal to null!!. </p>
  
  <p>When I added a break point to see all lines list contents, I got as in the following image :</p>
  
  <p><a href="https://i.stack.imgur.com/KvlqX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KvlqX.png" alt="enter image description here"></a></p>
  
  <p>The above method needs to parse each group of levels separately!!. </p>