public static void main(String[] args) { String s = "awfcaf12344,ewef23esf4567,dbds234sdvgsg"; String[] ss = s.split("\\D"); int total = 0; for(int i = 0; i < ss.length; i++) { if(!"".equals(ss[i])) { total += Integer.parseInt(ss[i]); } } System.out.println(total); }
String s = "awfcaf12344,ewef23esf4567,dbds234sdvgsg"; String regex = "\\D*(\\d+)\\D*"; Matcher m = Pattern.compile(regex).matcher(s); int result = 0; while (m.find()) { result += Integer.parseInt(m.group(1)); } System.out.println(result);
public static void main(String[] args) {
String s = "awfcaf12344,ewef23esf4567,dbds234sdvgsg";
String[] ss = s.split("\\D");
int total = 0;
for(int i = 0; i < ss.length; i++) {
if(!"".equals(ss[i])) {
total += Integer.parseInt(ss[i]);
}
}
System.out.println(total);
}
String s = "awfcaf12344,ewef23esf4567,dbds234sdvgsg";
String regex = "\\D*(\\d+)\\D*";
Matcher m = Pattern.compile(regex).matcher(s);
int result = 0;
while (m.find()) {
result += Integer.parseInt(m.group(1));
}
System.out.println(result);