后台通过查询得到一跳数据,格式如下 [234],想的到数字,马上想到用String类处理
String base = "[234]";
base = base.replace("[", "").replace("]", "");
回头看,正则用的很少,就试着用正则来处理
String base = "[234]";
String regex = "\\[(\\d*)\\]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(base);
if(matcher.find()&&matcher.groupCount()>0) {
String count = matcher.group(1);
}
这样就得到数字了,matcher.find()这个方法必须调用,要不就不能得到分组的字符串,