I have a string that has some Environment.Newline in it. I'd like to strip those from the string and instead, replace the Newline with something like a comma.
我有一个字符串,里面有一些Environment.Newline。我想从字符串中删除它们,而是用逗号替换Newline。
What would be, in your opinion, the best way to do this using C#.NET 2.0?
在您看来,使用C#.NET 2.0的最佳方法是什么?
5 个解决方案
#1
17
Why not:
string s = "foobar\ngork";
string v = s.Replace(Environment.NewLine,",");
System.Console.WriteLine(v);
#2
7
Like this:
string s = "hello\nworld";
s = s.Replace(Environment.NewLine, ",");
#3
2
Don't reinvent the wheel - just use myString.Replace(Environment.NewLine, ",")
不要重新发明* - 只需使用myString.Replace(Environment.NewLine,“,”)
#4
2
string sample = "abc" + Environment.NewLine + "def";
string replaced = sample.Replace(Environment.NewLine, ",");
#5
0
The best way is the builtin way: Use string.Replace
. Why do you need alternatives?
最好的方法是内置方式:使用string.Replace。你为什么需要替代品?
#1
17
Why not:
string s = "foobar\ngork";
string v = s.Replace(Environment.NewLine,",");
System.Console.WriteLine(v);
#2
7
Like this:
string s = "hello\nworld";
s = s.Replace(Environment.NewLine, ",");
#3
2
Don't reinvent the wheel - just use myString.Replace(Environment.NewLine, ",")
不要重新发明* - 只需使用myString.Replace(Environment.NewLine,“,”)
#4
2
string sample = "abc" + Environment.NewLine + "def";
string replaced = sample.Replace(Environment.NewLine, ",");
#5
0
The best way is the builtin way: Use string.Replace
. Why do you need alternatives?
最好的方法是内置方式:使用string.Replace。你为什么需要替代品?