title: How to split a string into a array of arrays of strings as fast as possible in C#?
body: <p><strong>Short description:</strong> Splitting a string takes way to long.</p>
  <p><strong>Longer description:</strong>
  I need to <strong>extract information from a string</strong> looking like this:</p>
  <pre><code>...
  5   1   12  1   1   1   466 1277    458 80  92  Assistance
  2   1   13  0   0   0   1055    1277    1717    100 -1  
  3   1   13  1   0   0   1055    1186    1717    191 -1  
  4   1   13  1   1   0   1055    1277    1717    100 -1  
  5   1   13  1   1   1   1055    1279    288 78  90  Vehicle
  5   1   13  1   1   2   1489    1279    228 98  67  Lights
  5   1   13  1   1   3   1856    1281    286 95  74  System
  5   1   13  1   1   4   2284    1281    196 95  70  Apps
  5   1   13  1   1   5   2618    1277    154 80  77  Info
  ...
  </code></pre>
  <p>(Side Note: the string comes as a return from the <strong>page.GetTsvText(0)</strong> method; page is a return of <strong>TesseractEngine.Process(image)</strong>; so the string contains information about <strong>detected OCR strings</strong>, <strong>conficendes</strong>, <strong>bounding boxes coords</strong>, etc.)</p>
  <p>In order to be able to make easier use of the information, I wrote a method that <strong>turns the string into a array of arrays of strings</strong>:</p>
  <pre><code>private string[][] getDataArray(string source)
          {
              Stopwatch sw = new Stopwatch();
              sw.Start();
  
              Console.WriteLine(source);
  
              string[] rows = source.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
              int nrOfRows = rows.Length;
              string[][] result = new string[nrOfRows][];
  
              for (int i = 0; i &lt; nrOfRows; i++)
              {
                  result[i] = rows[i].Split(new char[] { ' ', '   ' }, StringSplitOptions.RemoveEmptyEntries);
              }
              sw.Stop();
              Console.WriteLine(&quot; $$$ getDataArray() took: &quot; + sw.ElapsedMilliseconds + &quot; ms&quot;);
              return result;
          }
  </code></pre>
  <p><strong>Note:</strong> For some reason the string contains spaces that look longer than the usual spaces. I took it with copy-paste from the console log. It is a single character, not a tab, but it takes more space/ is wider than the usual space char.</p>
  <p><strong>Problem:</strong></p>
  <ul>
  <li>When I measure the time <strong>from inside</strong> the method, it takes <strong>less than 1 ms</strong>.</li>
  <li>When I measure the time <strong>from outside</strong>, like this:</li>
  </ul>
  <pre><code>stopwatch.Restart();
  
  
  // Get data
  string[][] data = getDataArray(page.GetTsvText(0));
  
  stopwatch.Stop();
  Console.WriteLine(&quot; $$$ $$$ Got data array in: &quot; + stopwatch.ElapsedMilliseconds + &quot; ms&quot;);
  </code></pre>
  <p>it takes about <strong>2000 ms</strong>.</p>
  <p><strong>Does the string initialisation take so long</strong>? <strong>How can I get it faster, like under 50 ms</strong>?</p>