查看: 451  |  回复: 0
  VB6 查看字符的Unicode和Ansi
楼主
发表于 2023年4月18日 18:41

新建From1(窗体),Command1(按钮CommandButton),代码:

Private Sub Command1_Click()
    Dim str_Input As String
    str_Input = "码农库ma"
    
    Dim strAnsi As String
    Dim strUnicode As String
    strUnicode = "码农库ma"
    strAnsi = StrConv(strUnicode, vbFromUnicode)
    
    str_Input = str_Input & Chr(13)
    str_Input = str_Input & "Unicode:" & str(Len(strUnicode)) & Chr(13)
    str_Input = str_Input & "Ansi:" & str(LenB(strAnsi))
    
    Debug.Print str_Input
End Sub

运行结果:

码农库ma
Unicode: 5
Ansi: 8

关于编码可以看下《ASCII ANSI Unicode UTF-8 UTF-16等字符编码的区别

1楼
发表于 2023年4月24日 14:54

新建From1(窗体),新建Command1和2(按钮CommandButton),代码:

Dim byteAry() As Byte
Dim str5 As String

Private Sub Command1_Click()
    Dim i As Long
    str5 = "码abc"
    byteAry = str5

    For i = LBound(byteAry) To UBound(byteAry)
        Debug.Print byteAry(i)    '得 1 120 97 0 98 0 99 0
    Next i
    
    Debug.Print Len(str5), LenB(str5)    '得4 8
End Sub

Private Sub Command2_Click()
    '所以了,可看出UniCode 的特性,程式应改一下,使用Strconv()来转换 Dim byteAry() As Byte
    Dim str5 As String
    Dim i As Long
    str5 = "码abc"
    
    byteAry = StrConv(str5, vbFromUnicode)
    For i = LBound(byteAry) To UBound(byteAry)
        Debug.Print byteAry(i)    '得 194 235 97 98 99
    Next i
    
    Debug.Print LenB(StrConv(str5, vbFromUnicode))    '得5
End Sub


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com