I have a string which I would like to split on a particular delimiter and then remove starting and trailing whitespace from each member. Currently the code looks like:
string s = "A, B, C ,D";
string[] parts = s.Split(',');
for(int i = 0; i++; i< parts.Length)
{
parts[i] = parts[i].Trim();
}
I feel like there should be a way to do this with lambdas, so that it could fit on one line, but I can't wrap my head around it. I'd rather stay away from LINQ, but I'm not against it as a solution either.
string s = "A, B, C ,D";
string[] parts = s.Split(','); // This line should be able to perform the trims as well
I've been working in Python recently and I think that's what has made me revisit how I think about solutions to problems in C#.
string[] parts = s.Split(new[] { ", " }, StringSplitOptions.None);