• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Differentiating between newline escape characters and carriage returns

 
Greenhorn
Posts: 2
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear team,

I am trying to write code for reading files with text content. The problem is that the string values which I have contain both new line escape characters as well as carriage returns. I need to get my strings rid of the carriage returns only and not the new line escape characters. Could some one please help me out here?

System.out.println("START- " + dataString + " -END");
System.out.println();
System.out.println("START- " + dataString.replaceAll("\\n","") + " -END");
System.out.println();
System.out.println("START- " + dataString.replaceAll("\\r", "") + " -END"); --- doesn't work

The output is:


START- Configure synchronization and upload of all processes or specific process
Configure synchronization and upload of all processes or specific process -END

START- Configure synchronization and upload of all processes or specific process Configure synchronization and upload of all processes or specific process -END

START- Configure synchronization and upload of all processes or specific process
Configure synchronization and upload of all processes or specific process -END
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't escape the \. \r has special meaning (carriage return) in both Java and in regular expressions.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Abdullah Akbar
Greenhorn
Posts: 2
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Rob and Campbell.


 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic