Today I was wondering if there is a better solution to execute the following code example.
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){
Is there a way to execute trim () without manually repeating each element? I am looking for something like "split by the following characters and automatically crop every result."
Ah, right before the publication I found
List<string> parts = line.Split(';').Select(p => p.Trim()).ToList();
in How can I split and trim a string into pieces on the same string?
Nevertheless, I am curious: maybe there is a better solution? (Or does the compiler possibly convert them to the same code output as Linq-Operation?)
string c # trim
citronas Dec 29 '09 at 10:30 p.m. 2009-12-29 22:30
source share