2008-08-24 26 views

Respuesta

17

Por qué no:

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

La mejor manera es la forma integrada: use string.Replace. ¿Por qué necesitas alternativas?

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

No reinventar la rueda - sólo tiene que utilizar myString.Replace (Environment.NewLine "")

7

De esta manera:

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