I am trying to remove a last character of a string. This last character is a newline (System.Environment.NewLine).
I have tried some things, but I can not remove it.
Example:
myString.Remove(sFP.Length - 1)
Example 2:
myString= Replace(myString, Environment.NewLine, "", myString.Length - 1)
How I can do it?
If your newline is CR LF, it’s actually two consecutive characters. Try your
Removecall withLength - 2.If you want to remove all “\n” and “\r” characters at the end of string, try calling
TrimEnd, passing the characters:To remove all the whitespace characters (newlines, tabs, spaces, …) just call
TrimEndwithout passing anything.