java替换字符串
替换“dsBBfvAAxcvAAasxcBBB" 里的AA和BB为空串的方法,真实字符串可能很长,求最高效方法
[解决办法]
replaceAll不行么?
[解决办法]
"AsABdBCCDDAAsBBsAABBVV".replaceAll("A{2}|B{2}", "")
[解决办法]
String s = "dsBBfvAAxcvAAasxcBBB";s.replace("AA","").replace("BB","");
[解决办法]
String str = "dsBBfvAAxcvAAasxcBBB"; System.out.println(str.replaceAll("AA|BB",""));
[解决办法]
import org.apache.commons.lang.StringUtils;public class Test{ public static void main(String args[]){ System.out.println(StringUtils.replaceEach("dsBBfvAAxcvAAasxcBBB",new String[]{"AA","BB"}, new String[]{"",""})); }}