<script language="VBScript"> 'http://www.linuxforum.net/books/UTF-8-Unicode.html Public Function UTF8EncodeChar(z) Dim c : c=AscW(z)'取UNICODE编码 if c>0 And c<256 Then'Asc编码直接返回 UTF8EncodeChar=z Exit Function End If If c<0 Then c=c + &H10000&'VBScript的Integer溢出,加上 Dim k : k=CLng(c)'备份一个编码,后面判断要用 Dim b() Dim i : i=0 While c>&H0&'将编码按照6位一组,分组存到字节数组 b 中 ReDim Preserve b(i) b(i)=CByte(c And &H3F&) c=c / &H40& i=i+1 Wend If UBound(b)>0 Then '如果分开的6位组不止一个,除最高一组外,全部加上二进制10000000 For i=0 To UBound(b)-1 b(i)=b(i) + &H80 Next End If i=UBound(b)'根据字符的UNICODE编码范围,给最高组加上前缀 If k<=CLng(&H7F&) Then b(i) = b(i) + 0 ElseIf k<=CLng(&H7FF&) Then b(i) = b(i) + &HC0 ElseIf k<=Clng(&HFFFF&) Then b(i) = b(i) + &HE0 ElseIf k<=CLng(&H1FFFFF&) Then b(i) = b(i) + &HF0 ElseIf k<=CLng(&H3FFFFFF&) Then b(i) = b(i) + &HF8 Else b(i) = b(i) + &HFC End If UTF8EncodeChar="" For i=UBound(b) To 0 Step -1'将分组转换成URL编码 UTF8EncodeChar=UTF8EncodeChar & "%" & Right("00" & Hex(b(i)),2) Next Erase b End Function Public Function UTF8EncodeString(s) Dim i,l,c : l=Len(s) For i=1 To l UTF8EncodeString=UTF8EncodeString & UTF8EncodeChar(Mid(s,i,1)) Next End Function MsgBox UTF8EncodeString("圪圪 eglic ") </script>