45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:转换javascript vbscript编码的方法

转换javascript vbscript编码的方法

2016-09-02 12:57:44 来源:www.45fan.com 【

转换javascript vbscript编码的方法

方法一:

functiongb2utf8(data){
varglbEncode=[];
gb2utf8_data=data;
execScript("gb2utf8_data=MidB(gb2utf8_data,1)","VBScript");
vart=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t=t.split("@");
vari=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k])
{
gb2utf8_char=eval("0x"+k);
execScript("gb2utf8_char=Chr(gb2utf8_char)","VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data=gb2utf8_char=null;
returnunescape(t.join("%"));
}

使用时:xxx.innerHTML=gb2utf8(req.responseBody);

方法二.

Functionbytes2BSTR_GB2312(vIn)
strReturn=""
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR_GB2312=strReturn
EndFunction

方法三:
<scriptlanguage="JavaScript">
<!--
functionutf8(wide){
varc,s;
varenc="";
vari=0;
while(i<wide.length){
c=wide.charCodeAt(i++);
//handleUTF-16surrogates
if(c>=0xDC00&&c<0xE000)continue;
if(c>=0xD800&&c<0xDC00){
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s<0xDC00||c>=0xDE00)continue;
c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
//outputvalue
if(c<0x80)enc+=String.fromCharCode(c);
elseif(c<0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
elseif(c<0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
elseenc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
returnenc;
}
varhexchars="0123456789ABCDEF";
functiontoHex(n){
returnhexchars.charAt(n>>4)+hexchars.charAt(n&0xF);
}
varokURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
functionencodeURIComponentNew(s){
vars=utf8(s);
varc;
varenc="";
for(vari=0;i<s.length;i++){
if(okURIchars.indexOf(s.charAt(i))==-1)
enc+="%"+toHex(s.charCodeAt(i));
else
enc+=s.charAt(i);
}
returnenc;
}
alert(encodeURIComponentNew("中文"))
alert(decodeURIComponent(encodeURIComponentNew("中文")))
//-->
</script>
方法一:

functiongb2utf8(data){
varglbEncode=[];
gb2utf8_data=data;
execScript("gb2utf8_data=MidB(gb2utf8_data,1)","VBScript");
vart=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t=t.split("@");
vari=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k])
{
gb2utf8_char=eval("0x"+k);
execScript("gb2utf8_char=Chr(gb2utf8_char)","VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data=gb2utf8_char=null;
returnunescape(t.join("%"));
}

使用时:xxx.innerHTML=gb2utf8(req.responseBody);

方法二.

Functionbytes2BSTR_GB2312(vIn)
strReturn=""
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR_GB2312=strReturn
EndFunction

方法三:
<scriptlanguage="JavaScript">
<!--
functionutf8(wide){
varc,s;
varenc="";
vari=0;
while(i<wide.length){
c=wide.charCodeAt(i++);
//handleUTF-16surrogates
if(c>=0xDC00&&c<0xE000)continue;
if(c>=0xD800&&c<0xDC00){
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s<0xDC00||c>=0xDE00)continue;
c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
//outputvalue
if(c<0x80)enc+=String.fromCharCode(c);
elseif(c<0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
elseif(c<0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
elseenc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
returnenc;
}
varhexchars="0123456789ABCDEF";
functiontoHex(n){
returnhexchars.charAt(n>>4)+hexchars.charAt(n&0xF);
}
varokURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
functionencodeURIComponentNew(s){
vars=utf8(s);
varc;
varenc="";
for(vari=0;i<s.length;i++){
if(okURIchars.indexOf(s.charAt(i))==-1)
enc+="%"+toHex(s.charCodeAt(i));
else
enc+=s.charAt(i);
}
returnenc;
}
alert(encodeURIComponentNew("中文"))
alert(decodeURIComponent(encodeURIComponentNew("中文")))
//-->
</script>
方法一:

functiongb2utf8(data){
varglbEncode=[];
gb2utf8_data=data;
execScript("gb2utf8_data=MidB(gb2utf8_data,1)","VBScript");
vart=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
t=t.split("@");
vari=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k])
{
gb2utf8_char=eval("0x"+k);
execScript("gb2utf8_char=Chr(gb2utf8_char)","VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data=gb2utf8_char=null;
returnunescape(t.join("%"));
}

使用时:xxx.innerHTML=gb2utf8(req.responseBody);

方法二.

Functionbytes2BSTR_GB2312(vIn)
strReturn=""
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR_GB2312=strReturn
EndFunction

方法三:
<scriptlanguage="JavaScript">
<!--
functionutf8(wide){
varc,s;
varenc="";
vari=0;
while(i<wide.length){
c=wide.charCodeAt(i++);
//handleUTF-16surrogates
if(c>=0xDC00&&c<0xE000)continue;
if(c>=0xD800&&c<0xDC00){
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s<0xDC00||c>=0xDE00)continue;
c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
//outputvalue
if(c<0x80)enc+=String.fromCharCode(c);
elseif(c<0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
elseif(c<0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
elseenc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
returnenc;
}
varhexchars="0123456789ABCDEF";
functiontoHex(n){
returnhexchars.charAt(n>>4)+hexchars.charAt(n&0xF);
}
varokURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
functionencodeURIComponentNew(s){
vars=utf8(s);
varc;
varenc="";
for(vari=0;i<s.length;i++){
if(okURIchars.indexOf(s.charAt(i))==-1)
enc+="%"+toHex(s.charCodeAt(i));
else
enc+=s.charAt(i);
}
returnenc;
}
alert(encodeURIComponentNew("中文"))
alert(decodeURIComponent(encodeURIComponentNew("中文")))
//-->
</script>
 

本文地址:http://www.45fan.com/a/question/71293.html
Tags: JavaScript 编码 VBScript
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部