score:2

Accepted answer

Trim() only trims white spaces at the start and end (leading and trailing) of the string... See docs

To remove white spaces within a string you can use:

  • *str*.Replace(" ", "");
  • Regex.Replace(*str*, @"\s", "")

where str is the string.

Also consider using a comparison method such as *str*.Equals(*str2*, StringComparison.OrdinalIgnoreCase) instead of relying on ToUpper(). Read How to compare strings in C#, it explains string comparison in detail.


Related Articles