I have a string coming from UI that may contains control characters, and I want to remove all control characters except carriage returns, line feeds, and tabs.
Right now I can find two way to remove all control characters:
1- using guava:
return CharMatcher.JAVA_ISO_CONTROL.removeFrom(string);
2- using regex:
return string.replaceAll("\p{Cntrl}", "");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…