In the Find box hold down the Alt key and type 0 1 0 for the line feed and Alt 0 1 3 for the carriage return. They can now be replaced with whatever you want.
Method 2: Use the strip() Function to Remove a Newline Character From the String in Python. The strip() method in-built function of Python is used to remove all the leading and trailing spaces from a string. Our task can be performed using strip function() in which we check for “\n” as a string in a string.
The canonical way to strip end-of-line (EOL) characters is to use the string rstrip() method removing any trailing \r or \n.
This will trim off any combination of carriage returns and newlines from the end of s
:
s = s.TrimEnd(new char[] { '\r', '\n' });
Edit: Or as JP kindly points out, you can spell that more succinctly as:
s = s.TrimEnd('\r', '\n');
This should work ...
var tst = "12345\n\n\r\n\r\r";
var res = tst.TrimEnd( '\r', '\n' );
If you are using multiple platforms you are safer using this method.
value.TrimEnd(System.Environment.NewLine.ToCharArray());
It will account for different newline and carriage-return characters.
String temp = s.Replace("\r\n","").Trim();
s
being the original string. (Note capitals)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With