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

lea*_*ner 0 java string split

String s = "Total Count :2, Correct Count :1, Wrong Count:1, Correct :India is great,, Wrong: where aer you";
Run Code Online (Sandbox Code Playgroud)

我想要的是:

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

int变量中.

这对我来说还是个新鲜事,我希望你们能帮助我.

Phi*_*nov 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
Run Code Online (Sandbox Code Playgroud)