Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to catch \n in a string.

Status
Not open for further replies.

chags

Programmer
Dec 4, 2000
12
US
In a string i want to replace '\n'(next line) to ' '(space). So I tried the following code but it not even identifing '\n'
Code:
String test = "sending data \n to excell \n";
test.replace('\n',' ');

If anyone knows how to catch \n in a string please help me.
 
Hi,

It did identify '\n' :)

The reason why is isn't working is because the method replace() doesn't change the String. It returns a String with the changed value instead.

So this would work:-

String test = "sending data \n to excell \n";
test = test.replace('\n',' ');

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Hi Leon,

Its working fine with your suggested syntax. Thanks for helping me.

Chags
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top