JAVA字符串替换
JAVA字符串替换
?import java.util.StringTokenizer;
?? public String str_replace(String from,String to,String source) {
???? StringBuffer bf= new StringBuffer("");
???? StringTokenizer st = new StringTokenizer(source,from,to);
???? while (st.hasMoreTokens()) {
?????? String tmp = st.nextToken();
?????? if(tmp.equals(from)) {
???????? bf.append(to);
?????? } else {
???????? bf.append(tmp);
?????? }
???? }
???? return bf.toString();
?? }