上次的问题没解决,请问jsp的替换函数是什么

lgmsyy 2002-04-28 07:42:41
请问jsp的替换函数是什么?就如replace()
能否给举个正确的例子谢谢。

有个人是这样回答的,但是我编译的时候出错,另外如何用他呢,格式是不是replace("abcd","ab","123");


<%
public String replace(String s,String oldStr,String newStr)
{
while ( s!= null && (s.indexOf(oldStr) != -1) )
{
s = s.substring(0,s.indexOf(oldStr)) + newStr + s.substring(s.indexOf(oldStr) + oldStr.length());
}
return s;
}
%>
...全文
32 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgmsyy 2002-04-28
  • 打赏
  • 举报
回复
但是编译的时候还是出现下列错误:
提示错误如下:
javax.servlet.ServletException: Compilation error occured:
Found 4 errors in JSP file:

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token
scarab 2002-04-28
  • 打赏
  • 举报
回复
replace(char oldChar, char newChar)
替换的是字符串的某一字符
如果要替换字符串要自己加上循环
packy_li 2002-04-28
  • 打赏
  • 举报
回复
有些错误提示是不正确的,你可以用BufferString进行替换,具体的可在csdn上搜索
lgmsyy 2002-04-28
  • 打赏
  • 举报
回复
还是不行总提示上面的错误。
replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token
到底是什么意思啊。
可乐加水 2002-04-28
  • 打赏
  • 举报
回复
String st="sfafasfafafd";
String tmp=st.replace(char,char);
这个语法好像可以
lgmsyy 2002-04-28
  • 打赏
  • 举报
回复
提示错误如下:
javax.servlet.ServletException: Compilation error occured:
Found 4 errors in JSP file:

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

replace.jsp:2: Syntax: ; expected instead of this token

lgmsyy 2002-04-28
  • 打赏
  • 举报
回复
我当然想找些收贴子不过我得问个明白。
谁让我是初学者。
Andrawu 2002-04-28
  • 打赏
  • 举报
回复
那当然了,自己写的函数嘛。
可乐加水 2002-04-28
  • 打赏
  • 举报
回复
<%int i;
String str="mynameishu";
String rstr="name";
String rstrit="brother";
for (i=0;i<=str.length();i++)
{
if(str.startsWith(rstr,i))
break;
}
String tmp1=str.substring(0,i);
out.println(tmp1);
String tmp2=str.substring(i+rstr.length());
out.println(tmp2);
String nowstr=tmp1+rstrit+tmp2;

out.println(nowstr);
// String tmp=str.
%>
绝对好使
tin_dra 2002-04-28
  • 打赏
  • 举报
回复
贴上你的jsp程序

81,117

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧