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

时间:2014-04-11 09:30:29

标签: java string split

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

我想要的是什么:

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

int变量中。

对我来说这是一个新手,我希望你们能帮助我。

1 个答案:

答案 0 :(得分:5)

    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