Solved

Remove newline from string

Posted on 2007-04-10
5
1,563 Views
Last Modified: 2012-05-05
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
Comment
Question by:Rowdyone52
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Yttribium
ID: 18883192
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
 

Author Comment

by:Rowdyone52
ID: 18883203
Still doesnt replace with "+"
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
ID: 18883223
string x = "This is a test\r\nof the \r\nnewline character.";
x = x.Replace("\r\n", "+");
0
 
LVL 5

Expert Comment

by:Yttribium
ID: 18883268
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
 
LVL 16

Expert Comment

by:AlexNek
ID: 18883342
Why not?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question