在C#中,可以使用Replace
方法來去掉字符串中的換行符。例如:
string originalString = "Hello\nWorld!";
string stringWithoutNewLines = originalString.Replace("\n", "");
Console.WriteLine(stringWithoutNewLines); // Output: HelloWorld!
這樣就可以去掉字符串中的換行符。如果需要同時去掉回車符\r
,也可以使用類似的方法將其替換為空字符串。