Use regular expressions to remove English from a string
String str = "111,AAA,222,BBB"; Pattern p = pattern.compile ("[a-za-z]");//Create Stringbuff to splice stringbuffer sb = new StringBuffer (); string[] s = str. Split (","); for (int i = 0; i < s.length; i++) { //If there are English letters I do not handle this side, if there is a need, you can add the If (P.matcher (s) [i]). Find ()) { //does not contain the English alphabet }else{ //is stitched into a new string, judging if the current index is not the last one, add "," if (I < s.length-1) { After stitching up the string) Sb.append (S[i] + ","); } else { //If it is the last one, add sb.append (S[i]) directly ; }}} Verify that the last digit contains "," this occurs because the last character contains the English, I did not handle, the penultimate character in the concatenation, because not the last, so will add a "," String SBS = Sb.tostring (); if (Sbs.endswith (",")) { SBS = sbs.substring (0,sbs.length ()-1); } SYSTEM.OUT.PRINTLN (SBS);
Output Result:
111,222