I tried the following code in LINQPad and got the results given below:
List<string> listFromSplit = new List<string>("a, b".Split(",".ToCharArray())).Dump();
listFromSplit.ForEach(delegate(string s)
{
s.Trim();
});
listFromSplit.Dump();
"a" and " b"
so the letter b didn't get the white-space removed as I was expecting...?
Anyone have any ideas
[NOTE: the .Dump() method is an extension menthod in LINQPad that prints out the contents of any object in a nice intelligently formatted way]
you're just creating a trimmed string, not assigning anything to it.
var s = " asd ";
s.Trim();
won't update s, while..
var s = " asd ";
s = s.Trim();
will..
var listFromSplit = "a, b".Split(',').Select(s=>s.Trim());
would, i suppose, be how i'd go about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With