2011-05-04 3 views

답변

1
// Your input looks like this. 
String s = "[name ;24, name;23, name;22]"; 

String[] numberStrings = s 
    // First get rid of the known prefix and suffix 
    .substring("[name ;".length(), s.length - "]".length()) 
    // Then split on the repeated portion that occurs between numbers. 
    .split(", name;"); 
3
String s = "[name ;24, name;23, name;22]"; 
String couples[] = s.replace("]", "").split(","); 
int ages[] = new int[couples.length]; 
for (int i=0; i< couples.length; i++) 
    ages[i] = Integer.parseInt(couples[i].split(";")[1]); 
0

또 다른 방법

String str = "name ;24, name;23, name;22"; 
int p = 0; 
while ((p = str.indexOf(";", p + 1)) > -1) { 
    System.out.println(str.substring(p+1).split("[^0-9]")[0]); 
} 
관련 문제