/** * * 返回非字母和数字 + 字母数字(26*2个字母 + 10个数字) * 诸如“中国abc123”将被分成“中国”和“abc123” * 而且约定中文总是在前的! * * @param source * @return 2个字符串 */ public static String[] splitter(final String source) { String[] tokens = null; int index = 0; for (int i = 0; source != null && i < source.length(); i++) { char c = source.charAt(i); System.out.println(i + ": " + c); System.out.println(">>>>" + Integer.toHexString(c)); //判断受否字母和数字 if ( (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { index = i; break; } }
//可以分组 if (index > 0) { tokens = new String[] {source.substring(0, index), source.substring(index)}; } else { //没有可分 tokens = new String[] {source, null}; } return tokens; }
1.getChar 2.设定分割符 3.split期待某高人的正则~:) 顺便捞点分~
just have a try, not very sure....Pattern p = Pattern.compile("([\u4E00-\u9FA5]+)([0-9|a-z|A-Z]+)"); while(m.find){ String chinese = m.group(1); String num_letter = m.group(2); }
*
* 返回非字母和数字 + 字母数字(26*2个字母 + 10个数字)
* 诸如“中国abc123”将被分成“中国”和“abc123”
* 而且约定中文总是在前的!
*
* @param source
* @return 2个字符串
*/
public static String[] splitter(final String source) {
String[] tokens = null;
int index = 0;
for (int i = 0; source != null && i < source.length(); i++) {
char c = source.charAt(i);
System.out.println(i + ": " + c);
System.out.println(">>>>" + Integer.toHexString(c));
//判断受否字母和数字
if ( (c >= '0' && c <= '9')
|| (c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z')) {
index = i;
break;
}
}
//可以分组
if (index > 0) {
tokens = new String[] {source.substring(0, index), source.substring(index)};
} else { //没有可分
tokens = new String[] {source, null};
}
return tokens;
}
2.设定分割符
3.split期待某高人的正则~:)
顺便捞点分~
while(m.find){
String chinese = m.group(1);
String num_letter = m.group(2);
}
String[] s=str.split("[\u4E00-\u9FA5]+");
不可限定内容,内容包括字母数字和中文,具体情况无限制。但是看来只有用自己判断char的方法来做了。
to dztc() :你的方法显然不行
while(m.find){
String chinese = m.group(1);
String num_letter = m.group(2);
}
这个应该可以哦
Matcher m = p.matcher(yourString);//之前少了这句
while(m.find){
String chinese = m.group(1);
String num_letter = m.group(2);
}难道我这个不行吗?
Matcher m = p.matcher(yourString);//之前少了这句
while(m.find){
String chinese = m.group(1);
String num_letter = m.group(2);
}
他的这个肯定行啊。。