Link to home
Start Free TrialLog in
Avatar of Computer Guy
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?


                string folder = folderName[i].ToLower();
                folder.Replace(" ", string.Empty);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of p_davis
p_davis

are you opposed to regex?
Regex.Replace(folder , @"\s+", "")
>> ... 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+", "")
that's why we are supposed to comment our code.
regex isn't always the best answer but it is flexible.