当前位置:文章中心 - ASP编程 - VBScript实现的escape和unescape功能函数
相关文章
这里放搜索
最新文章
VBScript实现的escape和unescape功能函数
关键词:escape,unescape 时间:2009年06月06日 星期六 阅读:100
  1. <script language="vbscript">  
  2. 'escape时不变的7个符号: *(42) +(43) -(45) .(46) /(47) @(64) _(95)  
  3.  
  4. Function vbsEscape(str)  
  5.     dim i,s,c,a  
  6.     s=""  
  7.     For i=1 to Len(str)  
  8.         c=Mid(str,i,1)  
  9.         a=ASCW(c)  
  10.         If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then  
  11.             s = s & c  
  12.         ElseIf InStr("@*_+-./",c)>0 Then  
  13.             s = s & c  
  14.         ElseIf a>0 and a<16 Then  
  15.             s = s & "%0" & Hex(a)  
  16.         ElseIf a>=16 and a<256 Then  
  17.             s = s & "%" & Hex(a)  
  18.         Else  
  19.             s = s & "%u" & Hex(a)  
  20.         End If  
  21.     Next  
  22.     vbsEscape = s  
  23. End Function  
  24. Function vbsUnEscape(str)  
  25.     dim i,s,c  
  26.     s=""  
  27.     For i=1 to Len(str)  
  28.         c=Mid(str,i,1)  
  29.         If Mid(str,i,2)="%u" and i<=Len(str)-5 Then  
  30.             If IsNumeric("&H" & Mid(str,i+2,4)) Then  
  31.                 s = s & CHRW(CInt("&H" & Mid(str,i+2,4)))  
  32.                 i = i+5  
  33.             Else  
  34.                 s = s & c  
  35.             End If  
  36.         ElseIf c="%" and i<=Len(str)-2 Then  
  37.             If IsNumeric("&H" & Mid(str,i+1,2)) Then  
  38.                 s = s & CHRW(CInt("&H" & Mid(str,i+1,2)))  
  39.                 i = i+2  
  40.             Else  
  41.                 s = s & c  
  42.             End If  
  43.         Else  
  44.             s = s & c  
  45.         End If  
  46.     Next  
  47.     vbsUnEscape = s  
  48. End Function  
  49. document.writeln vbsEscape("蓝雨")  
  50. document.writeln vbsUnEscape("%u84DD%u96E8")  
  51. document.writeln "<br>"  
  52. document.writeln (vbsEscape("~`!@#$%^&*()_+-={}|[]\:"";'<>?,./"))  
  53. </script> 
  1. <script language="javascript">  
  2. document.writeln(escape("蓝雨"))  
  3. document.writeln(unescape("%u84DD%u96E8"))  
  4. document.writeln("<br>")  
  5. document.writeln(escape("~`!@#$%^&*()_+-={}|[]\\:\";'<>?,./"))  
  6. </script>  
上一篇:精妙SQL语句介绍下一篇:没有了

0条记录访客评论

暂未有任何评论,你来发表一篇吧!

发表评论

(必填)
(必填)
 
友情链接