日期:2014-05-20  浏览次数:20727 次

字符串替换
如下面的一个字符串,想把内容ABC替换成hello.
<string name="STR_ABC">ABC</string>
最后结果:
<string name="STR_ABC">hello</string>
请问怎么更好更快地实现替换!
string 替换

------解决方案--------------------
public class tihuan {
public static void main(String[] args){
String s="<string name=\"STR_ABC\">ABC</string>";
System.out.println(s.replaceAll("(<.*>)ABC(<.*>)","$1hello$2" ));
}
}


------解决方案--------------------
方法太多
		String s = "<string name=\"STR_ABC\">ABC</string>";
System.out.println(s.replace(">ABC<", ">hello<"));

------解决方案--------------------
没事再来一个

public class tihuan {
public static void main(String[] args) {
String s = "<string name=\"STR_ABC\">ABC</string>";
System.out.println(s.replaceAll("(?<=>)\\w+(?=<)", "hello"));
}
}