可以使用正则表达式来匹配字符串中的数字,然后使用字符串的substring方法截取数字后面的部分,例如:

String str = 'abc123def456';
String regex = '\d+';
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
    String result = str.substring(matcher.start());
    System.out.println(result);
}

这段代码会输出:'123def456',也就是从字符串中第一个数字开始截取后面的部分。

Java 字符串截取: 从第一个数字开始

原文地址: https://www.cveoy.top/t/topic/mJyB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录