Java examples for java.lang:String Replace
replace all in a string
//package com.java2s; public class Main { public static void main(String[] argv) { String src = "java2s.com"; String from = "oo"; String to = "00"; System.out.println(replaceall(src, from, to)); }/*ww w.j a v a2s . co m*/ public static String replaceall(String src, String from, String to) { StringBuffer tmp = new StringBuffer(src); int length = from.length(); int index = tmp.toString().indexOf(from); while (index > 0) { tmp.replace(index, index + length, to); index = tmp.toString().indexOf(from); } return tmp.toString(); } }