I have the string like:
TEST FURNITURE-34_TEST>
My requirement is to remove all those junk characters from the above string. so my expected output will be:
TEST FURNITURE-34_TEST
I have tried the below code
public static String removeUnPrintableChars(String str) {
if (str != null) {
str = str.replaceAll("[^\\x00-\\x7F]", "");
str = str.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "");
str = str.replaceAll("\\p{C}", "");
str = str.replaceAll("\\P{Print}", "");
str = str.substring(0, Math.min(256, str.length()));
str = str.trim();
if (str.isEmpty()) {
str = null;
}
}
return str;
}
But it does nothing. Instead of finding and replacing each character as empty, can anyone please help me with the generic solution to replace those kinds of characters from the string?