What is the easiest way in C# to trim a newline off of a string?

c#, string

Solution

The following works for me.

sb.ToString().TrimEnd( '\r', '\n' );

or

sb.ToString().TrimEnd( Environment.NewLine.ToCharArray());

Problem

I want to make sure that _content does not end with a NewLine character: ``` _content = sb.ToString().Trim(new char[] { Environment.NewLine }); ``` but the above code doesn't work since Trim seems to not have an overloaded parameter for a collection of strings, only characters. What is the simplest one-liner to remove an Enivronment.Newline from the end of a string?

Original source