[已解决]VBA更改txt文件“编码格式”为UTF 您所在的位置:网站首页 excel生成编码 [已解决]VBA更改txt文件“编码格式”为UTF

[已解决]VBA更改txt文件“编码格式”为UTF

2024-07-16 11:26| 来源: 网络整理| 查看: 265

試試 轉化 UTF-8

Private Function GetUTF8String(s As String) As String    Dim i As Integer    Dim utf16 As Long, uc(2) As Byte        GetUTF8String = ""    For i = 1 To Len(s)        utf16 = AscW(Mid(s, i, 1))        If utf16 < 0 Then utf16 = utf16 + 65536        If utf16 < &H80 Then ' 1 Byte            GetUTF8String = GetUTF8String & Chr(utf16)        ElseIf utf16 < &H800 Then ' 2 Byte            uc(1) = &H80 + (utf16 And &H3F) ' Least Significant 6 bits            utf16 = utf16 \ &H40 ' Shift UTF16 number right 6 bits            uc(0) = &HC0 + (utf16 And &H1F) ' Use 5 remaining bits            GetUTF8String = GetUTF8String & Chr(uc(0)) & Chr(uc(1))        Else ' 3 Byte            uc(2) = &H80 + (utf16 And &H3F) ' Least Significant 6 bits            utf16 = utf16 \ &H40 ' Shift UTF16 number right 6 bits            uc(1) = &H80 + (utf16 And &H3F) ' Use next 6 bits            utf16 = utf16 \ &H40 ' Shift UTF16 number right 6 bits again            uc(0) = &HE0 + (utf16 And &HF) ' Use 4 remaining bits            GetUTF8String = GetUTF8String & Chr(uc(0)) & Chr(uc(1)) & Chr(uc(2))        End If    NextEnd Function



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有