2013-10-29 60 views
0

的子串如何改變使用正則表達式「1 [AZ] +」(分裂以「X」)和碼使用的replaceAll() 例如一個字符串的子串:改變字符串的Java

"this is an example 1one" 

應出示:

"this is an example 1Xone" 

回答

1

試試這個:

class Test { 
    public static void main(String[] args) { 
    String str = "this is an example 1one"; 
    str = str.replaceAll("1([a-z]+)", "1X$1"); 
    System.out.println(str); 
    } 
}