Removing invisible characters from the end of a Java String

冷暖自知 提交于 2021-02-19 08:02:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!