public static String cleanString(String src){
  if (src == null) {
    return null;
  }
  boolean foundBad=false;
  final CharacterIterator it=new StringCharacterIterator(src);
  for (char c=it.first(); c != CharacterIterator.DONE; c=it.next()) {
    if (c < ASCII_PRINTABLE_LOW || c >= ASCII_PRINTABLE_HI) {
      foundBad=true;
      break;
    }
  }
  if (!foundBad) {
    return src;
  }
  final StringBuilder res=new StringBuilder();
  for (char c=it.first(); c != CharacterIterator.DONE; c=it.next()) {
    if (c < ASCII_PRINTABLE_LOW || c >= ASCII_PRINTABLE_HI) {
      res.append(ASCII_SPACE);
    }
 else {
      res.append(c);
    }
  }
  return res.toString();
}

public static String cleanString ( String src ) { if ( src == null ) { return null ; } boolean foundBad = false ; final CharacterIterator it = new StringCharacterIterator ( src ) ; for ( char c = it . first ( ) ; c != CharacterIterator . DONE ; c = it . next ( ) ) { if ( c < ASCII_PRINTABLE_LOW || c >= ASCII_PRINTABLE_HI ) { foundBad = true ; break ; } } if ( ! foundBad ) { return src ; } final StringBuilder res = new StringBuilder ( ) ; for ( char c = it . first ( ) ; c != CharacterIterator . DONE ; c = it . next ( ) ) { if ( c < ASCII_PRINTABLE_LOW || c >= ASCII_PRINTABLE_HI ) { res . append ( ASCII_SPACE ) ; } else { res . append ( c ) ; } } return res . toString ( ) ; }
returns a string based on the input string , but with all characters with ordinal values < 32 or > = 128 replaced with ' ' .
