• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1573
  • Last Modified:

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."
0
Rowdyone52
Asked:
Rowdyone52
  • 2
  • 2
1 Solution
 
YttribiumCommented:
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?
0
 
Rowdyone52Author Commented:
Still doesnt replace with "+"
0
 
AlexNekCommented:
string x = "This is a test\r\nof the \r\nnewline character.";
x = x.Replace("\r\n", "+");
0
 
YttribiumCommented:
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
0
 
AlexNekCommented:
Why not?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now