public class BinaryIODemo {
public static void main(String[] args){
String a = new String("hello ll llo");
System.out.println(a.replaceAll("ll ","world "));
}
}
public static void main(String[] args){
String a = new String("hello ll llo");
System.out.println(a.replaceAll("ll ","world "));
}
}
String a = new String("hello world llo");另一个途径就是从新负值
import java.util.regex.*;
public class BinaryIODemo {
public static void main(String[] args){
String a = new String("ll hello ll llo ll");
System.out.println(a.replaceAll("^(ll)|(ll)$|\\s+(ll)\\s+"," world "));
}
}
public class Test{
public static void main(String[] arg){
String str="ABCD1234EFG123";
System.out.println(str.replaceAll("(\\d){4}","XXXX"));
}
}可是我的值是在一个变量里的,我就改了一吓:
yettake = yettake.replaceAll("(\\aaa ){4}","");
但是在运行没有替换`应该怎样写才对?
你的这个问题,我上面的程序是可以的,不管你的ll在那里!
还区别ll与oll(或其他)字符吗?
我再改一下,就可以了 !
import java.util.regex.*;
public class BinaryIODemo {
public static void main(String[] args){
String a = new String("llhello ll sllo ll");
System.out.println(a.replaceAll("^(ll)\\s+|\\s+(ll)$|\\s+(ll)\\s+"," world "));
}
}
不然的话 thinking in java第3版,12章的最后也有讲,不过这些只是入门的东西 !