温馨提示×

c#字符串怎么去掉换行符

c#
小亿
204
2024-08-12 08:28:31
栏目: 编程语言

在C#中,可以使用Replace方法来去掉字符串中的换行符。例如:

string originalString = "Hello\nWorld!";
string stringWithoutNewLines = originalString.Replace("\n", "");

Console.WriteLine(stringWithoutNewLines); // Output: HelloWorld!

这样就可以去掉字符串中的换行符。如果需要同时去掉回车符\r,也可以使用类似的方法将其替换为空字符串。

0