You want to use String.Replace
to remove a character.
s = s.Replace("\n", String.Empty);
s = s.Replace("\r", String.Empty);
s = s.Replace("\t", String.Empty);
Note that String.Trim(params char[] trimChars)
only removes leading and trailing characters in trimChars
from the instance invoked on.
You could make an extension method, which avoids the performance problems of the above of making lots of temporary strings:
static string RemoveChars(this string s, params char[] removeChars) {
Contract.Requires<ArgumentNullException>(s != null);
Contract.Requires<ArgumentNullException>(removeChars != null);
var sb = new StringBuilder(s.Length);
foreach(char c in s) {
if(!removeChars.Contains(c)) {
sb.Append(c);
}
}
return sb.ToString();
}