C# 如何 将字符串后面的换行去掉
可以使用 String.TrimEnd() 方法来去掉字符串末尾的空格和换行符。
示例代码:
string str = "hello world\n";
str = str.TrimEnd('\n');
Console.WriteLine(str); // 输出 "hello world"
该方法可以接受一个 char 数组作为参数,表示要去掉的字符集合。在本例中,我们将 '\n' 作为参数传入,表示要去掉换行符。
原文地址: https://www.cveoy.top/t/topic/bU0o 著作权归作者所有。请勿转载和采集!