我有一个字符串,里面有一些Environment.Newline。我想从字符串中删除它们,而是用逗号替换Newline。

在您看来,使用C#.NET 2.0的最佳方法是什么?

有帮助吗?

解决方案

为什么不:

string s = "foobar\ngork";
string v = s.Replace(Environment.NewLine,",");
System.Console.WriteLine(v);

其他提示

像这样:

string s = "hello\nworld";
s = s.Replace(Environment.NewLine, ",");

不要重新发明轮子 - 只需使用myString.Replace(Environment.NewLine,",")

string sample = "abc" + Environment.NewLine + "def";
string replaced = sample.Replace(Environment.NewLine, ",");

最好的方法是内置方式:使用 string.Replace 。你为什么需要其他选择?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top