如何匹配字符串中的数字整数并返回整数值?例如:
String = "Color Red, Size 32 / Text text";我想从这个字符串中得到"32“整数值。
在此之前,非常感谢您。
问候你,Koko
发布于 2011-07-27 21:53:37
public static void main(String[] args) {
String s = "Color Red, Size 32 / Text text";
Matcher matcher = Pattern.compile("\\d+").matcher(s);
if (matcher.find()) {
String find = matcher.group();
Integer i = Integer.parseInt(find);
}
}发布于 2011-07-27 21:51:23
试试这段代码
Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*");
Matcher m = p.matcher("Testing1234Testing");
if (m.find()) {
System.out.println(m.group(1));
}https://stackoverflow.com/questions/6845399
复制相似问题