trim()
function does NOT remove “all whitespace characters” of your string. So instead of trim(), you can use String.Replace method:
string str = "C Sharp"; str = str.Replace(" ", ""); OUTPUT: CSharp
or if you want to remove all whitespace characters (space, tabs, line breaks…)
string str = "C Sharp"; str = Regex.Replace(str, @"\s", ""); OUTPUT: CSharp