Filter out the punctuation marks in the string. in development, we may encounter this situation, that is, remove a character from the string.
PHP code
@ Test public void test () {String d = trimPunctuation2 ("Hello oewefo, 21.2 !; :, 1? Dsf "); System. out. println (d);} // filter out the punctuation marks in the String public static String trimPunctuation2 (String str) {String punct [] = {",",". ","! ","? ",";",":",",",". ","! ","? ","; ",": ",", "}; List
PunctList = Arrays. asList (punct); // Convert String array to List set StringBuilder result = new StringBuilder (); for (int I = 0; I <str. length (); I ++) {Character c = str. charAt (I); if (punctList. contains (c. toString () {} else {result. append (str. charAt (I) ;}} return result. toString () ;}// filter out the punctuation marks in the String public static String trimPunctuation (String str) {StringBuilder result = new StringBuilder (); for (int I = 0; I <str. length (); ++ I) {char punct [] = {',','.','! ','? ',';',':',',','. ','! ','? ','; ',': ',', '}; Boolean need_filter = false; for (int j = 0; j <punct. length; ++ j) {if (punct [j] = str. charAt (I) {need_filter = true; break ;}} if (! Need_filter) {result. append (str. charAt (I) ;}} return result. toString ();}