title: Remove whitespaces in c# without any built in functions
body: <p>Hi I am a beginner in C# and I was trying to remove the whitespaces in a string.
  I use the following code:</p>
  
  <pre><code>public String RemoveSpace(string str1)
  {
  
      char[] source = str1.ToCharArray();
  
      int oldIndex = 0;
      int newIndex = 0;
      while (oldIndex &lt; source.Length)
      {
          if (source[oldIndex] != ' ' &amp;&amp; source[oldIndex] != '\t')
          {
              source[newIndex] = source[oldIndex];
              newIndex++;
          }
          oldIndex++;
      }
      source[oldIndex] = '\0';
      return new String(source);
  
  }
  </code></pre>
  
  <p>But the problem I'm facing is when I give the 
  <strong>input string as "H e l"</strong> 
  <strong>the output shows "Hel l"</strong>
  which is because the at the last iteration <code>oldIndex</code> is at <code>arr[2]</code> being replaced by <code>arr[4]</code> and the last character 'l' is being left out. Can some one point out the mistake that is being done? 
  Note: There should not be any use of Regex, trim or replace functions.
  Thanks.</p>