StrConv无法正常运行

时间:2017-04-21 08:17:51

标签: excel vba locale

我有一个代码将输入转换为ascii字符串。

asciiString = ""
For charIndex = 1 To Len(pInput)
    character = Mid(pInput, charIndex, 1)
    ascii = Asc(character)
    If (ascii < 0) Then
        asciiString = asciiString & StrConv(character, vbFromUnicode)
    Else
        asciiString = asciiString & Chr(ascii)
    End If
Next charIndex

从excel读取pInput时,它就像A / C:ABCD 如果A / C:ABCD(单字节)它工作正常,但如果A / C:ABCD(双字节)它输出类似A / C ????

我可以知道如何纠正吗?

PS:我的电脑是日语语言环境

一些更新:

For charIndex = 1 To LenB(pInput) Step 2
    character = MidB(pInput, charIndex, 2)
    ascii = Asc(character)
    If (ascii < 0) Then
        asciiString = asciiString & StrConv(StrConv(character, vbFromUnicode), vbUnicode)

    Else
        asciiString = asciiString & Chr(ascii)
    End If
Next charIndex

有效。

For charIndex = 1 To Len(pInput)
    character = Mid(pInput, charIndex, 1)
    ascii = Asc(character)
    If (ascii < 0) Then
        asciiString = asciiString & StrConv(StrConv(character, vbFromUnicode), vbUnicode)

    Else
        asciiString = asciiString & Chr(ascii)
    End If
Next charIndex

它也有效。

For charIndex = 1 To Len(pInput)
    character = Mid(pInput, charIndex, 1)
    ascii = Asc(character)
    If (ascii < 0) Then
        asciiString = asciiString & StrConv(character, vbFromUnicode)

    Else
        asciiString = asciiString & Chr(ascii)
    End If
Next charIndex

失败.asciiString返回“A / C䄺䐀伥䄀”

我不太了解窗口中的编码系统, 但我需要确保代码适用于“日语”语言环境和“英语”语言环境,请帮助我!非常感谢!!

0 个答案:

没有答案