Posted on 2007-03-13 17:36
锋出磨砺 阅读(336)
评论(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();
}