Posted on 2007-03-13 17:36
鋒出磨礪 閱讀(341)
評論(0) 編輯 收藏 所屬分類:
java算法
public static String replaceStr(String source,String toBeReplaced,String replaceWith)
??? {??? ?
??? ?StringBuffer buffer = new StringBuffer();
??? ?
??? ?StringTokenizer st = new StringTokenizer(source,toBeReplaced);
??? ?if(st.countTokens()>0)
??? ?{
??? ??while(st.hasMoreTokens())
??? ??{
??? ???String token = st.nextToken();
??? ???buffer.append(token);
??? ???buffer.append(replaceWith);
??? ??}
??? ?}
??? ?else
??? ?{
??? ??//nothing to replace
??? ??buffer.append(source);
??? ?}
??? ???? ?
??? ?return buffer.toString();
??? }