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

后端 未结 10 1522
无人及你
无人及你 2020-12-13 03:11

I want to make sure that _content does not end with a NewLine character:

_content = sb.ToString().Trim(new char[] { Environment.NewLine });

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 03:40

    The following works for me.

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

    or

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

提交回复
热议问题