2014-04-11 1 views
0
String s = "Total Count :2, Correct Count :1, Wrong Count:1, Correct :India is great,, Wrong: where aer you"; 

:문자열 분할 얻을 내가 원하는 일부 데이터

  • 총 수
  • 올바른 카운트
  • 잘못된 카운트 int 변수

.

이것은 나에게 상당히 새롭다, 너희들이 나를 도울 것이기를 바랍니다.

+0

[API] (http://docs.oracle.com/javase/7/docs/api/java/lang/String.html)를 읽었습니까? – PakkuDon

+1

내가 원하는 것 : http://img0.gtsstatic.com/wallpapers/c789639a11a000fc0e9d2438962de741_large.jpeg – ruhungry

답변

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 
+0

@aashish_soni, 원하는 것이면 내 대답을 받아 들여야한다.) –

+0

@aashish_soni, 나는 이것을 의미했다 : http : //i.stack.imgur.com/uqJeW.png –