gpt4 book ai didi

Java匹配器数字方法

转载 作者:行者123 更新时间:2023-11-30 07:32:04 25 4
gpt4 key购买 nike

如何匹配字符串中的数字整数并返回整数值。?例如;

String = "Color Red, Size 32 / Text text";

我想从这个字符串中得到“32”整数值。

非常感谢。

问候, cocoa

最佳答案

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);
}
}

关于Java匹配器数字方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6845399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com