當前位置:編程學習大全網 - 電腦編程 - JAVA中如何從字符串中提取壹個整數

JAVA中如何從字符串中提取壹個整數

java中從字符串中提取壹個整數,壹個個的對字符串比較效率太低,需要使用正則表達式進行匹配,如下代碼:

String?str?=?"金額:88,687,594元";

Pattern?p?=?Pattern.compile("\\d+(,\\d{3})*");

Matcher?m?=?p.matcher(str);

if(m.find()){

System.out.println(m.group());

}

  • 上一篇:c# UDP編程怎麽連接路由器內的電腦
  • 下一篇:亞太杯數學建模競賽和美賽哪個難些
  • copyright 2024編程學習大全網