• Post Reply Bookmark Topic Watch Topic
  • New Topic

CR / LF remove  RSS feed

 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried every possible combination:

\r\n
\\r\\n
[\\r\\n]
\\r|\\n

etc ...

I am not able to remove <CF><LF> to a string

 
Ron McLeod
Saloon Keeper
Posts: 1600
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the sequence is <CR><LF> then it will be your second pattern: \\r\\n

Do you have some simple code which shows it not working as expected?
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible that you committed the beginner error that almost all of us have committed, namely not assigning the result of the replaceAll method to a new String? I notice that your posted code just discards the result, rather than assigning it to a variable, so maybe your real code has the same problem.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Is it possible that you committed the beginner error that almost all of us have committed, namely not assigning the result of the replaceAll method to a new String?

I have certainly committed that one.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simone giusti wrote:I am not able to remove <CF><LF> to a string

Can I ask why you want to do this?

If it's an exercise for class, then obviously you should do what you've been asked to; but <CF><LF> is a very particular construct:
  Specifically: it is the line terminator used by Microsoft products.
So removing them from a line that was generated by something else may still leave behind control characters that you may not want.

Basically, what you're doing is a "one-trick pony" solution for something that may well be a more general problem - ie, removing line terminators however they are supplied.

So, before you go too far down this road, I'd work out exactly what it is you want to do.

And also look at the docs for BufferedReader.readLine() and Scanner.nextLine(), the latter of which can also be used on Strings.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!