[分享]VBS实现Unicode(UTF-16)转UTF-8

2014年7月28日星期一 | | 0 评论 |

有UTF-8转Unicode当然就有Unicode转UTF-8。

'Author: Demon  'Website: http://demon.tw  'Date: 2010/9/28  Function UnicodeToUtf8(str)      Dim i, c, length      out = ""      length = Len(str)      For i = 1 To length          c = CLng("&H" & Hex(AscW(Mid(str,i,1))))          If (c >= &H0001) And (c <= &H007F) Then              out = out & ChrB(c)          ElseIf c > &H07FF Then              out = out & ChrB(&HE0 Or (c\(2^12) And &H0F))              out = out & ChrB(&H80 Or (c\(2^ 6) And &H3F))              out = out & ChrB(&H80 Or (c\(2^ 0) And &H3F))          Else              out = out & ChrB(&HC0 Or (c\(2^ 6) And &H1F))              out = out & ChrB(&H80 Or (c\(2^ 0) And &H3F))          End If      Next      UnicodeToUtf8 = out  End Function  

参考链接:UTF-8 – 维基百科,自由的百科全书

http://demon.tw/programming/vbs-unicode-to-utf8.html


所有文章收集于网络,如果有牵扯到版权问题请与本站站长联系。谢谢合作![email protected]