Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to remove strange control characters from a string

807606Apr 5 2007 — edited Apr 6 2007
Hi,

I am using some legacy swing application, and every time I use ctrl-v or ctrl-c, there is a strange control character generated (it looks like a square/rectangle) at the end of the string. I cannot paste this special character here while I can easily do it in Eclipse IDE. The problem is, if I replace \u007F with this special character, I cannot use replaceAll("[\u007F]","") to remove it from the string, while I can remove it if the string contains unicode representation such as
"first\u007F". I am wondering how I can remove it from string when it does not have unicode representation. Thanks.
public class ControlCharacterTest {
	public static void main(String[] args){
		char controlChar = '\u007F';
		String cChar = new Character(controlChar).toString();
		System.out.println("Control char == " + cChar);
		
                String input = "first";
		String newInput = input.replaceAll ("[\u007F]","");
		System.out.println("newInput == " + newInput);
		
		String newInput2 = input.replaceAll ("[\u0000-\u0020]","");
		System.out.println("newInput2 == " + newInput2);
	}
}
null

Message was edited by:
jack_wns

null
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2007
Added on Apr 5 2007
2 comments
571 views