• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issues while using String.replaceAll method  RSS feed

 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

While getting the output from a input stream, I am getting a host of garbage character sequences: 

These are probably escape sequences for a VT100 terminal emulator.

I am trying to use the String.replaceAll method to get rid of these sequences.



However, when I try to run this, I get an exception:


Can anyone tell me how can I use this method ? I just intend to replace the escape sequences by a blank.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first parameter is a regex (and not just a string value). In regular expressions, the open square brace has special meaning. You will need to escape it.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option is to use the replace() method instead -- the one that takes two strings.

Henry
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:Another option is to use the replace() method instead -- the one that takes two strings.

Actually two CharSequences, but String implements CharSequence so it's still a valid method for this situation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!