• Post Reply Bookmark Topic Watch Topic
  • New Topic

remove control characters  RSS feed

 
shekar rakju
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to remove control characters from a string ? ( control Z, etc..,). If some one has any code please send it to me.
Thanks in advance,
Shekar
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The java.util.regex.Pattern class documents the pattern syntax used by the replaceAll() command.
 
shekar rakju
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
But I am using jdk 1.3 . It don't have java.util.regex.Pattern class available. Please let me know the alternative as early as possible.
Thanks in advance,
Satya
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered simply looping through the chars in the string, and adding all non-control chars to a StringBuffer? Control chars are values 0-31 plus 127. Though that range includes some values you may actually wish to include:
9 :Ctrl-I : tab
10 : Ctrl-J : newline
13 : Ctrl-M : carriage return
You can decide if you really want to strip out newlines, etc, or maybe just replace them with a space or something.
 
sravani gogineni
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Yingst wrote:
The java.util.regex.Pattern class documents the pattern syntax used by the replaceAll() command.



Can i use str.replaceAll(System.getProperty("line.separator"," ")); instead?
This is one and the same?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The first string is a regular expression. You'd need to write a regex to match the characters you want to replace.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find a list of line end characters in the java.util.regex.Pattern class documentation., There are only about six of them, so you can easily make them into a regex.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!