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');
More Related Contents:
- What is the difference between a “line feed” and a “carriage return”?
- Escape double quotes in a string
- Can I convert a C# string value to an escaped string literal?
- Why would you use String.Equals over ==? [duplicate]
- Get string between two strings in a string
- String output: format or concat in C#?
- Differences in string compare methods in C#
- Efficient way to remove ALL whitespace from String?
- Comparing two strings, ignoring case in C# [duplicate]
- How to replace multiple white spaces with one white space
- Convert JSON String to JSON Object c#
- Is there an alternative to string.Replace that is case-insensitive?
- Can I “multiply” a string (in C#)?
- Java equivalents of C# String.Format() and String.Join()
- Need to perform Wildcard (*,?, etc) search on a string using Regex
- Is String a primitive type?
- How to split a number into individual digits in c#? [duplicate]
- C# equivalent to Java’s charAt()?
- How to capitalize the first character of each word, or the first character of a whole string, with C#?
- What is the correct way to compare char ignoring case?
- Convert XmlDocument to String
- How do I get the last four characters from a string in C#?
- Do string literals get optimised by the compiler?
- How do I format a Decimal to a programatically controlled number of decimals in c#?
- Regex nested parentheses
- Does C# have a String Tokenizer like Java’s?
- Convert String^ in c# to CString in c++/CLI
- Replace non-numeric with empty string
- How can I check if a string contains a character in C#?
- How to get the first five character of a String