title: Splitting/looping through a line that contains parentheses in c#
body: <p>I am working with the following line:</p>
  
  <pre><code>(SENT (VBP (HPP (HP Vem))(VB kan)(VBP (VB få)(PMP (PM ATP)))(MADP (MAD ?))))
  </code></pre>
  
  <p>I would like to make the following output:</p>
  
  <pre><code>SENT -&gt; VBP -&gt; HPP -&gt; HP
  SENT -&gt; VBP -&gt; VB
  SENT -&gt; VBP -&gt; VBP -&gt; VB
  SENT -&gt; VBP -&gt; VBP -&gt; PMP -&gt; PM
  SENT -&gt; VBP -&gt; MADP -&gt; MAD
  </code></pre>
  
  <p>To archieve this i first thought to loop through each parentheses, starting from the outest and then go deeper and deeper if any. (maybe a recursive function?)</p>
  
  <p>But since there is not really a function for splitting by parentheses, i tried splitting with <code>(</code> and then when looping through, look for <code>)</code>, like this:</p>
  
  <pre><code>    var row = "(SENT (VBP (HPP (HP Vem))(VB kan)(VBP (VB få)(PMP (PM ATP)))(MADP (MAD ?))))";
  
      string[] splitP = row.Split('(');
  
      for (int i = 0; i &lt; splitP.Length; i++ )
      {
          string data = splitP[i];
  
          // string[] dataSplit = data.Split(')');
  
          Console.WriteLine(data);
      }
  
      Console.ReadLine();
  </code></pre>
  
  <p>But as you can see, I got stuck and the above does not even represent of what i try to archeive - because i found out that the logic i was thinking is wrong and it can not be done like that.</p>
  
  <p>How can i archieve this?</p>
  
  <p>Update.</p>
  
  <p>A extra bigger test line:</p>
  
  <pre><code>(SENT (VBP (PPP (PP På)(NNP (NN grundval))(PPP (PP av))(NNP (DTP (DT en))(NN intervju)(PPP (PP efter)(NNP (NN experimentet)))(PPP (PP med)(PCP (DTP (DT de))(PC oinvigda)(VBP (HPP (HP som))(VB gjort)(NNP (JJP (JJ felaktiga))(NN bedömningar)))))))(VB kunde)(PNP (PN man))(VBP (VB dela)(PLP (PL in))(PNP (PN dem))(PPP (PP i)(NNP (RGP (RG tre))(NN grupper)(MIDP (MID :))(KNP (NNP (NN (a)))(PNP (PN de)(VBP (HPP (HP som))(ABP (AB faktiskt))(VB trodde)(SNP (SN att)(VBP (PNP (PN de))(VB bedömt)(ABP (AB riktigt))))))(MIDP (MID ,))(PNP (NNP (NN (b)))(PN de)(VBP (HPP (HP som))(VB trodde)(SNP (SN att)(VBP (DTP (DT de)(JJP (JJ själva)))(VB måste)(VBP (VB ha)(VBP (VB misstagit)(PNP (PN sig))(SNP (SN eftersom)(VBP (ABP (AB inte))(PNP (ABP (AB så))(PN många))(VB kan)(VBP (VB ha)(ABP (AB fel))(PPP (PP mot)(NNP (DTP (DT en))(JJP (JJ enda))(NN person))))))))))))(KN och)(PNP (NNP (NN (c)))(PN de)(KNP (VBP (HPP (HP som))(ABP (AB faktiskt))(VB var)(JJP (JJ medvetna))(PPP (PP om)(SNP (SN att)(VBP (PNP (PN de))(VB angav)(NNP (JJP (JJ felaktiga))(NN bedömningar))))))(KN men)(VBP (HPP (HP som))(ABP (AB inte))(VB ville)(VBP (VB avvika)(PPP (PP från)(NNP (NN gruppen)))))))))))(MADP (MAD .))))
  </code></pre>