ASP关于编码的几个有用的函数小结(utf8)

2019-01-13 03:40:08王冬梅

toUTF8 = szRet
End Function

3、'GB转unicode---将GB编码文字转换为unicode编码文字

function chinese2unicode(Str)
dim i
dim Str_one
dim Str_unicode
if(isnull(Str)) then
exit function
end if
for i=1 to len(Str)
Str_one=Mid(Str,i,1)
Str_unicode=Str_unicode&chr(38)
Str_unicode=Str_unicode&chr(35)
Str_unicode=Str_unicode&chr(120)
Str_unicode=Str_unicode& Hex(ascw(Str_one))
Str_unicode=Str_unicode&chr(59)
next
chinese2unicode=Str_unicode
end function

4、'URL解码

Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function

'判断是否为有效的十六进制代码
function isvalidhex(str)
dim c
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
%>

您可能感兴趣的文章:

Oracle将字符编码从GBK转到UTF8,如何操作比较稳妥?php字符编码转换之gb2312转为utf8PHP截断标题且兼容utf8和gb2312编码JoshChen_web格式编码UTF8-无BOM的小细节分析js 编码转换 gb2312 和 utf8 互转的2种方法基于php导出到Excel或CSV的详解(附utf8、gbk 编码转换)MySql修改数据库编码为UTF8避免造成乱码问题PHP utf-8编码问题,utf8编码,数据库乱码,页面显示输出乱码php验证手机号码(支持归属地查询及编码为UTF8)查看修改mysql编码方式让它支持中文(gbk或者utf8)真正根据utf8编码的规律来进行截取字符串的函数(utf8版sub_str )多种语言(big5gbkgb2312utf8Shift_JISiso8859-1)的网页编码切换解决方案归纳Mysql数据库编码问题 (修改数据库,表,字段编码为utf8)XMLHTTP 乱码的解决方法(UTF8,GB2312 编码 解码)PHP UTF8编码内的繁简转换类UTF8编码内的繁简转换的PHP类PHP 截取字符串 分别适合GB2312和UTF8编码情况utf8编码检测方法分享