title: How to trim whitespace from a managed String in C++/CLI
body: <p>I'm struggling to call the Trim() method on a managed string to remove any leading and trailing whitespace.</p>
  
  <p>I've tried:</p>
  
  <pre><code>System::String^ filename = "   export.csv   ";
  
  filename = System::String::Trim(filename);
  filename = filename::Trim();
  filename = filename.Trim();
  </code></pre>
  
  <p>This gives my errors of:</p>
  
  <p><code>error C2665: 'System::String::Trim' : none of the 2 overloads could convert all the argument types</code></p>
  
  <p>or</p>
  
  <p><code>error C2825: 'filename': must be a class or namespace when followed by '::'<br>
  error C2039: 'Trim' : is not a member of ''global namespace''<br>
  error C2146: syntax error : missing ';' before identifier 'Trim'<br>
  error C3861: 'Trim': identifier not found</code></p>
  
  <p>or</p>
  
  <p><code>error C2228: left of '.Trim' must have class/struct/union</code></p>
  
  <p>How are you supposed to trim a managed string in C++/CLI?  Why can't I use the <a href="http://msdn.microsoft.com/en-us/library/system.string.trim.aspx" rel="nofollow">System::String::Trim()</a> method?</p>