Refactoring existing code.
They are trying to collapse any series of spaces in string passed in to a single space.
Surely there is a better way.
for (int i = 0; i < 25; i++)
{
str = str.Replace(" ", " ");
}
Refactoring existing code.
They are trying to collapse any series of spaces in string passed in to a single space.
Surely there is a better way.
for (int i = 0; i < 25; i++)
{
str = str.Replace(" ", " ");
}
Split the string using
List<string> spiltList = yourStr.Split(' ').ToList();
Remove empty string from collection.
spiltList.RemoveAll(e => string.IsNullOrWhiteSpace(e));
Join the list of strings to a single string
string result = string.Join(" ", spiltList);