当前位置:首页 > JSP教程 > JSP常见问题

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

//
// 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();
}
}


// 使用方法
<jsp:usebean id="replace" scope="page" class="forum.strreplace" />
<%= replace.str_replace("<","^","<h1>123456</h1>") %> 
【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐