您的位置:首页 > 其它

有一个字符串,如"11.2美元34人民币";如何将数字与单位分开,放入数组中呢,数组比如 attr[0]=11.2 attr[1]=美元 ,依次类推

2013-11-16 23:05 316 查看
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test3 {
public static void main(String[] args) {
String s = "11.2美元34人民币";
String attr[] = new String[10];
Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+|\\d+\\.\\d+|\\d+");
Matcher m = p.matcher( s );
int index = 0;
while ( m.find() ) {
attr[index++] = m.group();
}
for(int j=0;j<index;j++){
System.out.println("attr["+ j + "] = " + attr[j]);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐