Reference document: http://www.linuxforum.net/books/UTF-8-Unicode.html
The code is as follows:
===========================================
The code copy is as follows:
<scriptlanguage="VBScript">
'http://www.linuxforum.net/books/UTF-8-Unicode.html
PublicFunctionUTF8EncodeChar(z)
Dimc:c=AscW(z)'Get UNICODE encoding
ifc>0Andc<256Then'Asc encoding directly returns
UTF8EncodeChar=z
ExitFunction
EndIf
Ifc<0Thenc=c+&H10000&'VBScript's Integer overflow, plus
Dimk:k=CLng(c)'Back up a code, and use it after the judgment
Dimb()
Dimi:i=0
Whilec>&H0&'Save the encoding into 6-bit groups and save the group into byte array b
ReDimPreserveb(i)
b(i)=CByte(cAnd&H3F&)
c=c/&H40&
i=i+1
Wend
IfUBound(b)>0Then'If there are more than one 6-bit group separated, except for the highest group, all binary 10000000 are added.
Fori=0ToUBound(b)-1
b(i)=b(i)+&H80
Next
EndIf
i=UBound(b)'Prefix the highest group according to the UNICODE encoding range of the character
Ifk<=CLng(&H7F&)Then
b(i)=b(i)+0
ElseIfk<=CLng(&H7FF&)Then
b(i)=b(i)+&HC0
ElseIfk<=Clng(&HFFFF&)Then
b(i)=b(i)+&HE0
ElseIfk<=CLng(&H1FFFFF&)Then
b(i)=b(i)+&HF0
ElseIfk<=CLng(&H3FFFFF&)Then
b(i)=b(i)+&HF8
Else
b(i)=b(i)+&HFC
EndIf
UTF8EncodeChar=""
Fori=UBound(b)To0Step-1' Converts the packet to URL encoding
UTF8EncodeChar=UTF8EncodeChar&"%"&Right("00"&Hex(b(i)),2)
Next
Eraseb
EndFunction
PublicFunctionUTF8EncodeString(s)
Dimi,l,c:l=Len(s)
Fori=1Tol
UTF8EncodeString=UTF8EncodeString&UTF8EncodeChar(Mid(s,i,1))
Next
EndFunction
MsgBoxUTF8EncodeString("听听听听听听")
</script>
Test method:
http://www.google.com/search?hl=zh-CN&newwindow=1&rls=GGLG%2CGGLG%3A2006-15%2CGGLG%3Azh-CN&q=Your code
The code copy is as follows:
functionrevertUTF8(szInput)
{
varx,wch,wch1,wch2,uch="",szRet="";
for(x=0;x<szInput.length;x++)
{
if(szInput.charAt(x)=="%")
{
wch=parseInt(szInput.charAt(++x)+szInput.charAt(++x),16);
if(!wch){break;}
if(!(wch&0x80))
{
wch=wch;
}
elseif(!(wch&0x20))
{
x++;
wch1=parseInt(szInput.charAt(++x)+szInput.charAt(++x),16);