日期:2014-05-20 浏览次数:20761 次
public void getInt(String str){ String[] arr = str.split("[^0-9]"); String s = ""; for(int i=0;i<arr.lenght;i++){ s+=arr[i]; } }
------解决方案--------------------
1.读取一行,放到变量line里面;
2.line = line.replaceAll("\\D", "");
3.line就是纯数字了。
------解决方案--------------------
public static void main(String[] args) { String str = "201 一般公共服务 " + "\r\n" + "202 外交" + "\r\n" + "2040101" + "\r\n" + "2010303" + "\r\n" + "201 一般公共服务" + "\r\n" + "202 外交" + "\r\n" + "2040101" + "\r\n" + "2010303" + "\r\n" ; Matcher matcher = Pattern.compile("\\d+").matcher(str); while (matcher.find()) { System.out.println(matcher.group()); } }