可以用正则:
import java.util.regex.*;
public class test {
public static void main( String[] args ) {
String s = "字符串123456哈哈441";
Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+|\\d+");
Matcher m = p.matcher( s );
while ( m.find() ) {
System.out.println( m.group() );
}
}
}
运行结果:
字符串
123456
哈哈
441
楼上的回答很正确, 也可以用Ascii码,,..如果把s中的123456赋予一个变量s1:try{
int s1 = Integer.parse(s);
}catch( NumberFormatException ex ){
}