Solved

Remove newline from string

Posted on 2007-04-10
5
1,567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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