title: How to remove all whitespace characters from a String?
body: <p>Dear fellow programmers,</p>
  
  <p>I am coding something in C# Visual Studio 2013 and I have just realized I might not need to use <code>Trim()</code> when I do <code>Replace(" ", string.Empty)</code>.</p>
  
  <p>An example follows:</p>
  
  <pre><code>SanitizedString = RawString
      .Replace("/", string.Empty)
      .Replace("\\", string.Empty)
      .Replace(" ", string.Empty)
      .Trim();
  </code></pre>
  
  <p>As I previously had this code structured differently, I haven't noticed it:</p>
  
  <pre><code>SanitizedString = RawString.Trim()
      .Replace("/", string.Empty)
      .Replace("\\", string.Empty)
      .Replace(" ", string.Empty);
  </code></pre>
  
  <p>I am aware these methods work different, as <code>Trim()</code> removes all whitespace characters, whereas <code>Replace(" ", string.Empty)</code> removes only space characters.</p>
  
  <p>That's why I have a different question.</p>
  
  <p>I don't see any obvious way to achieve that with Replace. My question is how would I go about it when I wish to remove all whitespace characters from the string?</p>
  
  <p>I found the following:</p>
  
  <p><a href="https://stackoverflow.com/a/6219488/1997354">Efficient way to remove ALL whitespace from String?</a></p>
  
  <p>But as I have never used regular expressions, I hesitate on how to apply it to string?</p>