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]);
}
}
}
有一个字符串,如"11.2美元34人民币";如何将数字与单位分开,放入数组中呢,数组比如 attr[0]=11.2 attr[1]=美元 ,依次类推
最新推荐文章于 2022-02-15 11:52:13 发布