File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Stripping Out Carriage Returns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stripping Out Carriage Returns" Watch "Stripping Out Carriage Returns" New topic

Stripping Out Carriage Returns

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1562
Why would the following code not take out the carriage returns and line feeds?

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Are you not asking it to replace only where there is a carriage return followed by a line break (plus I think you will need to escape the regex escape character)?

This does it I think:

[ May 08, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Or perhaps

str.replaceAll("[\\r\\n]+", "");

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Stripping Out Carriage Returns
It's not a secret anymore!