posts - 0, comments - 0, trackbacks - 0, articles - 1

(转)JAVA替换类

Posted on 2007-12-08 21:38 激进份子 阅读(229) 评论(0)  编辑  收藏 所属分类: JAVA
//
// StrReplace.java
//
package forum;
import java.util.*;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/

public class StrReplace {

public StrReplace() {
}
public String str_replace(String from,String to,String source)
{
StringBuffer bf= new StringBuffer("");
StringTokenizer st = new StringTokenizer(source,from,true);
while (st.hasMoreTokens())
{
String tmp = st.nextToken();
System.out.println("*"+tmp);
if(tmp.equals(from))
{
bf.append(to);
}
else
{
bf.append(tmp);
}
}
return bf.toString();
}
}

只有注册用户登录后才能发表评论。


网站导航: