2011-07-27 4 views
2

문자열에서 Digit Integer를 일치시키고 Integer 값을 반환하는 방법은 무엇입니까? 예 :Java Matcher Digit 메서드

String = "Color Red, Size 32/Text text"; 

이 문자열에서 "32"정수 값을 얻고 싶습니다.

미리 감사드립니다.

관련, 코코

답변

3
public static void main(String[] args) { 
    String s = "Color Red, Size 32/Text text"; 
    Matcher matcher = Pattern.compile("\\d+").matcher(s); 
    if (matcher.find()) { 
     String find = matcher.group(); 
     Integer i = Integer.parseInt(find); 
    } 
} 
에게 시도
0

이 코드

Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*"); 
Matcher m = p.matcher("Testing1234Testing"); 

if (m.find()) { 
    System.out.println(m.group(1)); 
} 
관련 문제