Dear fellow programmers,
I am coding something in C # Visual Studio 2013, and I just realized that I do not need to use Trim()when I do Replace(" ", string.Empty).
Example:
SanitizedString = RawString
.Replace("/", string.Empty)
.Replace("\\", string.Empty)
.Replace(" ", string.Empty)
.Trim();
Since I previously had this code structured differently, I did not notice it:
SanitizedString = RawString.Trim()
.Replace("/", string.Empty)
.Replace("\\", string.Empty)
.Replace(" ", string.Empty);
I know that these methods work differently, since it Trim()removes all whitespace, while it Replace(" ", string.Empty)only removes whitespace.
That is why I have another question.
I see no obvious way to achieve this with Replace. My question is, how can I do this when I want to remove all space characters from a string?
I found the following:
Efficient way to remove ALL spaces from a string?
, , ?