问题
how can i find the last visible character in a Java String? I'd like to remove all line breaks and other invisible characters from a Java String
Kind Regards, Tord
回答1:
You can use the trim() method of the String
class for removing trailing (and leading) white space and line breaks:
String trimmed = original.trim();
回答2:
string_variable.replaceAll("\\p{C}", "?");
This will replace all non-printable characters. Where p{C} selects the invisible control characters and unused code points.
来源:https://stackoverflow.com/questions/32685047/removing-invisible-characters-from-the-end-of-a-java-string