title: Perform Trim() while using Split()
body: <p>today I was wondering if there is a better solution perform the following code sample.</p>
  
  <pre><code>string keyword = " abc, foo  ,     bar";
  string match = "foo";
  string[] split= keyword.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
  foreach(string s in split)
  {
    if(s.Trim() == match){// asjdklasd; break;}
  }
  </code></pre>
  
  <p>Is there a way to perform trim() without manually iterating through each item? I'm looking for something like 'split by the following chars and automatically trim each result'. </p>
  
  <p>Ah, immediatly before posting I found</p>
  
  <pre><code>List&lt;string&gt; parts = line.Split(';').Select(p =&gt; p.Trim()).ToList();
  </code></pre>
  
  <p>in <a href="https://stackoverflow.com/questions/1728303/how-can-i-split-and-trim-a-string-into-parts-all-on-one-line">How can I split and trim a string into parts all on one line?</a></p>
  
  <p>Still I'm curious: Might there be a better solution to this? (Or would the compiler probably convert them to the same code output as the Linq-Operation?)</p>