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

后端 未结 10 1528
无人及你
无人及你 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:43

    I had to remove the new lines all over the text. So I used:

                while (text.Contains(Environment.NewLine))
                {
                    text = text.Substring(0, text.Length - Environment.NewLine.Length);
                }
    

提交回复
热议问题