title: How is String.Substring more efficient than String.Split?
body: <p><a href="http://web.archive.org/web/20130808085446/http://bluebytesoftware.com/blog/Default.aspx#aae7274ea-47f3-46e1-857d-f70361544ae4" rel="nofollow noreferrer">Joe Duffy's Blog</a> implies using <code>string.Substring</code> is more efficient than <code>string.Split</code>.</p>
  <p>I don't know if its saying the <code>Substring</code> method does not allocate a new string or if it is just more efficient because it does not make any unneeded allocations. Can you please explain how it is more efficient and show an example.</p>
  <p>I understand his first example as creating an array and then processing each of the strings in the array.</p>
  <pre><code>string str = ...;
  string[] substrs = str.Split(',');
  foreach (string subtr in substrs) {
  Process(substr);
  }
  </code></pre>
  <p>How is the following more efficient</p>
  <pre><code>string str = ...;
  int lastIndex = 0;
  int commaIndex;
  while ((commaIndex = str.IndexOf(',', commaIndex)) != -1) {
      Process(substr, lastIndex, commaIndex);
      lastIndex = commaIndex + 1;
  </code></pre>
  <p>What I see is using  <code>String.IndexOf</code> to find the index of the comma then processing the string. I assume he intends to use <code>String.Substring</code> to extract the data during his processing. One of the comments below suggested he may be pulling it character by character. Would he be pulling characters until he hits the next comma possibly building up an array of char?</p>