在做网站统计时,有时要统计来自google的关键词,就要对google关键词进行解码。如下函数可以实现此功能。
<%
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function
function ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0
for i=0 to ubound(A)
A(i)=c16to2(A(i))
next
for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
A(i)=right(A(i),len(A(i))-DigS)
Unicode=Unicode & A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode & A(i)
end if
next
if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end function
function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function
function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x
i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function
response.write UTF2GB("google%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D%E7%BC%96%E7%A0%81%E6%96%B9%E5%BC%8F")
%>
分享到:
相关推荐
二代身份证相片解码函数使用说明宣贯.pdf
C BASE64编解码函数,最近需要处理这方面的东西
语言配置不对,这个函数会出错的,另外,例子有点问题,换一个好了 int main() { unsigned char *str="新年快乐,Linux"; unsigned char ucs2str[1024],gbkstr[1024]; int len,i; len=EncodeUCS2(str,ucs2str);...
etpu旋变功能函数,其中包含旋变软解码功能函数接口
js中escape对应的C#解码函数 - Corrinejtt - ITeye
c语言写的base64编码函数和解码函数,经过严格测试,有测试代码。
Base64编码解码函数的VB实现。 无窗体,模块文件
相片解码函数使用说明
url rewrite 时,中文参数解决方法:用到的解码函数
谷歌的编解码工具,用于自动生成配置文件 根据proto文件生成Java代码
URL解码编码函数[URL解码编码函数]-精品源代码
基于matlab的QR码编码和解码函数,需要Java
javascript版本的 base64解码和编码函数。
提供两个函数,windows平台下的utf8编码解码 适用于unicode 和 ansi
文档包含基本的SMS解码编码函数集,供从事短消息开发的技术人员参考。
TS介绍,详细地介绍了数字电视中TS包解码函数注解
本文给大家分享了控制函数解码器电路图。
对ASP_UTF8_下(JS)中文乱码的解码函数 先用:bm()编码 在。request,或 enctype="multipart/form-data"类.FORM()获取时用JM()解码。
通过调用官方提供的DLL函数接口进行解码识别,C#完整源代码,识别速度极快!填充版解码结果请查阅源代码说明。
主要介绍了ASP编码和解码函数的相关资料,需要的朋友可以参考下