2007年1月9日 14:14
在接收网友提交的留言的时候,需要将回车符转化为“<br>”。可以使用mid()函数来“读取”段落中的每一个字符,然后用if then来判断是否含要替换的字符,最后使用加法+或连接符&将处理后的字符加起来,t1=t1+h。全部程序如下,例如<textarea>的文本域的名称是text:
这个原理,很多种语言都可适用,例如JavaScript、JScript、PHP、JSP、CGI都可以用这种思路做字符替换。
text=Request.Form("text")
t1=""
for i=1 to len(text)
h=mid(text,i,1)
if asc(h)=10 then h="<br>"
if asc(h)=13 then h=""
t1=t1+h
next
text=t1
text=server.HTMLEncode(text)
t1=""
for i=1 to len(text)
h=mid(text,i,1)
if asc(h)=10 then h="<br>"
if asc(h)=13 then h=""
t1=t1+h
next
text=t1
text=server.HTMLEncode(text)
这个原理,很多种语言都可适用,例如JavaScript、JScript、PHP、JSP、CGI都可以用这种思路做字符替换。
我们推荐您
快去试试吧!
asp中如何替换字符串?
页面中的图片超过规定的大小就按原图片大小缩小,不超过的就按原样的JS处理方案







