gpt4 book ai didi

java - 字符串拆分并获取一些数据

转载 作者:行者123 更新时间:2023-12-01 17:13:24 25 4
gpt4 key购买 nike

String s = "Total Count :2, Correct Count :1, Wrong Count:1, Correct :India is great,, Wrong: where aer you";

我想要什么:

  • 总计数
  • 正确计数
  • 计数错误

int 变量中。

这对我来说是相当新鲜的,希望你们能帮助我。

最佳答案

    String s = "Total Count :2, Correct Count :1,Wrong Count:1, Correct :India is great,, Wrong: where aer you";

String[] ints = s.split("[^0-9]+");

int totalCount = Integer.parseInt(ints[1]);
int correctCount = Integer.parseInt(ints[2]);
int wrongCount = Integer.parseInt(ints[3]);

System.out.println(totalCount + " " + correctCount + " " + wrongCount); //2 1 1

关于java - 字符串拆分并获取一些数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23008717/

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