来源(www.knowsky.com)

From: http://www.knowsky.com/2240.html

JSP中的字符替换函数 str_replace() 实现!

文章类别:JSP技巧 | 发表日期:2001-8-22 星期三 | 文章等级: ★★★★★

转自:动态网站制作指南 | www.knowsky.com//
// 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();
}
}

// 使用方法

<%= replace.str_replace("<","^","

123456

") %> 转自:动态网站制作指南 | www.knowsky.com

Link: http://www.asm32.net/article_details.aspx?id=1243