Possible Duplicate:
Removing carriage return and new-line from the end of a string in c#
How do I remove the carriage return at the end of string. I have already google out this but I cannot find the code I need.
This is my current code:
return s.Replace("\n", "").Replace("\r", "").Replace("\r\n", "").Trim();
but of course all the occurrence of the old character will be replaced.
I have tried these:
public string trim(string s) {
string[] whiteSpace = {"\r", "\n", "\r\n"};
foreach(string ws in whiteSpace)
{
if (s.EndsWith(ws))
{
s = s.Substring(0, s.Length - 1);
}
}
return s;
}
but is not working for me, maybe I miss something or there's a wrong with my code
I have also try using regular expression but I can't get what I need.
I get the string from word document then will be transfered to another docs.
I'll appreciate any help.Tnx