Computer Guy
asked on
Remove Spaces From String Array
Hi,
Some folder names are listed in an array like this: "Folder Name"
I want the result to be: "foldername"
This code below does not work. Any ideas?
Some folder names are listed in an array like this: "Folder Name"
I want the result to be: "foldername"
This code below does not work. Any ideas?
string folder = folderName[i].ToLower();
folder.Replace(" ", string.Empty);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> ... are you opposed to regex? ...
I'd guess that is a personal choice, based perhaps on readability & maintainabilty.
Most people (even non-programmers) can probably immediately see what is meant by
folder.Replace(" ", string.Empty)
but this is almost certainly not the case for:
Regex.Replace(folder , @"\s+", "")
I'd guess that is a personal choice, based perhaps on readability & maintainabilty.
Most people (even non-programmers) can probably immediately see what is meant by
folder.Replace(" ", string.Empty)
but this is almost certainly not the case for:
Regex.Replace(folder , @"\s+", "")
that's why we are supposed to comment our code.
regex isn't always the best answer but it is flexible.
Regex.Replace(folder , @"\s+", "")