字符串处理问题,请高手指点

yuchangmao 2003-06-08 09:48:43
我有一个试题录入页面,如果当我在试题内容文本框中输入一定的特殊字符或者是ASP敏感的字符串时,会不会出现错误?如果有错,请问如何解决?试题会提交到数据库中。

  毕业设计问题,请高手们多多照顾!
...全文
33 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
nattyfish 2003-06-08
  • 打赏
  • 举报
回复
用server.HTMLEncode(string),其中string为指定要编码的字符串.
虽然html可以显示大部分你写入asp文件中的文本,但是当你需要输入实际包含html标记中所使用的字符,或一定的特殊字符或者是ASP敏感的字符串时,就会出现问题.这是因为浏览器读到这样的字符时,会试图进行解释.
使用如下:
response.write server.HTMLEncode(content)
possible_Y 2003-06-08
  • 打赏
  • 举报
回复
server.HTMLEncode
denghan 2003-06-08
  • 打赏
  • 举报
回复
给你一个,参数着改一下
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i,j
j=0
for i = 1 to l
select case mid(str,i,1) 'mid(str,i,1)字串第i个字符后的1个字符
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
'result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
denghan 2003-06-08
  • 打赏
  • 举报
回复
你自己做个函数,把用户输入的字符先经过这个函数,把有可能出现的敏感字符尽量替换掉
popnew 2003-06-08
  • 打赏
  • 举报
回复
转义
yuchangmao 2003-06-08
  • 打赏
  • 举报
回复
请问还有其它方法吗?如果使用替换会很麻烦的,因为在试题录入中不知会出现怎么样的符号。
jackeyyang 2003-06-08
  • 打赏
  • 举报
回复
给个例子:
temp=replace(temp,"/","//")
ShiningstarHu 2003-06-08
  • 打赏
  • 举报
回复
将敏感字符替换掉!
Replace函数的用法自己去看一下。
hillhero789 2003-06-08
  • 打赏
  • 举报
回复
替换

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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