(Limitations: System; ONLY)
I want to be able to split a string into an array and remove the spaces, I have this currently:
string[] split = converText.Split(',').Select(p => p.Trim()).ToArray();
Also .ToArray
can't be used apparently.
But the problem is, I can't use anything other than core system methods. So how can I trim spaces from a split or array without using .select
or other non core ways?
string[] split =
convertText.Split(new[]{',',' '}, StringSplitOptions.RemoveEmptyEntries);
by adding a space to your split criteria, it will get rid of them when you have RemoveEmptyEntries. However this will fail if there are entries with spaces in them. In which case you could just :-
string[] split =
convertText.Split(new[]{','}, StringSplitOptions.RemoveEmptyEntries);
for (int index = 0; index < split.Count; index++)
{
split[index] = split[index].Trim();
}