VBScript实现的escape和unescape功能函数
关键词:escape,unescape 时间:2009年06月06日 星期六 阅读:196
- <script language="vbscript">
-
-
- Function vbsEscape(str)
- dim i,s,c,a
- s=""
- For i=1 to Len(str)
- c=Mid(str,i,1)
- a=ASCW(c)
- If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
- s = s & c
- ElseIf InStr("@*_+-./",c)>0 Then
- s = s & c
- ElseIf a>0 and a<16 Then
- s = s & "%0" & Hex(a)
- ElseIf a>=16 and a<256 Then
- s = s & "%" & Hex(a)
- Else
- s = s & "%u" & Hex(a)
- End If
- Next
- vbsEscape = s
- End Function
- Function vbsUnEscape(str)
- dim i,s,c
- s=""
- For i=1 to Len(str)
- c=Mid(str,i,1)
- If Mid(str,i,2)="%u" and i<=Len(str)-5 Then
- If IsNumeric("&H" & Mid(str,i+2,4)) Then
- s = s & CHRW(CInt("&H" & Mid(str,i+2,4)))
- i = i+5
- Else
- s = s & c
- End If
- ElseIf c="%" and i<=Len(str)-2 Then
- If IsNumeric("&H" & Mid(str,i+1,2)) Then
- s = s & CHRW(CInt("&H" & Mid(str,i+1,2)))
- i = i+2
- Else
- s = s & c
- End If
- Else
- s = s & c
- End If
- Next
- vbsUnEscape = s
- End Function
- document.writeln vbsEscape("蓝雨")
- document.writeln vbsUnEscape("%u84DD%u96E8")
- document.writeln "<br>"
- document.writeln (vbsEscape("~`!@#$%^&*()_+-={}|[]\:"";'<>?,./"))
- </script>
- <script language="javascript">
- document.writeln(escape("蓝雨"))
- document.writeln(unescape("%u84DD%u96E8"))
- document.writeln("<br>")
- document.writeln(escape("~`!@#$%^&*()_+-={}|[]\\:\";'<>?,./"))
- </script>
上一篇:
精妙SQL语句介绍下一篇:没有了
0条记录访客评论