I am building a string of last names separated by hyphens. Sometimes a whitespace gets caught in there. I need to remove all whitespace from end result.
Sample strin
Fastest and general way to do this (line terminators, tabs will be processed as well). Regex powerful facilities don't really needed to solve this problem, but Regex can decrease performance.
new string
(stringToRemoveWhiteSpaces
.Where
(
c => !char.IsWhiteSpace(c)
)
.ToArray()
)
OR
new string
(stringToReplaceWhiteSpacesWithSpace
.Select
(
c => char.IsWhiteSpace(c) ? ' ' : c
)
.ToArray()
)