Solved

Remove newline from string

Posted on 2007-04-10
5
1,560 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now