Link to home
Start Free TrialLog in
Avatar of Rowdyone52
Rowdyone52

asked on

Remove newline from string

Why does this not work?

string x = "This is a test\r\nof the \r\nnewline character."
x = x.Replace(@"\n", "+").Replace(@"\r", "");
Watch x still equals "This is a test\r\nof the \r\nnewline character."
Avatar of Yttribium
Yttribium

string ax = "This is a test\r\nof the \r\nnewline character.";
ax = ax.Replace('\n', '+').Replace("\r", "");
System.Diagnostics.Debug.WriteLine (ax);

Will this do?
Avatar of Rowdyone52

ASKER

Still doesnt replace with "+"
ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, I got the + on my string,
"This is a test+of the +newline character"
Forgot about putting it the way AlexNek, i.e. one call.

Anyway, as long as you get the solution
Why not?