CodePudding user response:
String regex="([\u4e00-\u9fa5]+)";
String STR="zhang SAN 1";
The Matcher Matcher=Pattern.com running (regex). The Matcher (STR);
If (the matcher. The find ()) {
System.out.println(matcher.group(0));
}
Refer to https://www.cnblogs.com/yaomajor/p/7001516.html
CodePudding user response:
If it is pure Chinese characters and then combined with pure digital form, refer to the following code:
String STR="zhang SAN 1";
Char [] chars=STR. ToCharArray ();
for(int i=0 ; iIf (Character. IsDigit (chars) [I]) {
System. The out. Println (STR. The substring (0, I));
break;
}
}
CodePudding user response:
String STR="zhang SAN 1";
StringBuffer words=new StringBuffer();
StringBuffer nums=new StringBuffer ();
Char [] chars=STR. ToCharArray ();
for(int i=0 ; iIf (Character. IsDigit (chars) [I]) {
nums.append(chars[i]);
} else {
Words. Append (chars [I]);
}
}
System.out.println(words);
CodePudding user response:
String s="10086" zhang SAN. ReplaceAll (" \ \ d + $", "");CodePudding user response: