// shall I write some keywords here to boost search engine ranking?

Sunday, September 28, 2008

Java: remove non-printable characters from String

Regular expression in Java is handy to remove non-printable character (control character, ASCII 0 - 31, 127) from a String:


String truncated = originalString.replaceAll("\\p{Cntrl}", "");

3 comments:

Anonymous said...

cough cough, bull crap

Anonymous said...

Non-printable crap didn't want to go throught xml, this fixed it, thanks!

Anonymous said...

Thank you!
Saved me from control-character ASCII #18/ HTML-escape %18.

greez Dreanaught