This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Search and replace \n in string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Search and replace \n in string" Watch "Search and replace \n in string" New topic

Search and replace \n in string

Pat Short

Joined: Mar 21, 2008
Posts: 22
Hi all,

I need to remove all \n from a string so that its output on one line. I can do this using the following

however, to improve the code and its portability i was wondering how I could use unicode to do this.

Any ideas.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38040
Good idea to think about portability and other operating systems

There is a list of possible line-end characters in the Pattern class; look for "line terminators." You can create a regular expression to match them.

That might be one way to solve your problem.
wood burning stoves
subject: Search and replace \n in string
Similar Threads
How can a Class create an instance of itself??
Trouble printing a filled array
catching null in a StringTokenizer
Help! Problems with a method calling itself...
create n number of variables of different name at runtime