开发者

Getting the unicode value of a char in VB

How can I get the unicode value of a char?

For example, I know that I can do this with ascii:

i = Asc("a") // i == 97 (correct)

What if I have a unicode char though?

i = Asc("•") // i == 149 (incorrect... should return 8226)

Obviously the second example doesn't work since that character is not in the Ascii set. Is there an e开发者_StackOverflow社区quivalent function that I can use which will return 8226 instead of the incorrect result 149?

I'm doing this in Outlook 2003, if that makes any difference.


What about AscW ?


The answer provided by RC. helped me a lot but I had issues with the AscW() function sometimes returning negative values.

In my case the problem appeared when working with Chinese characters.

I found a work around on the web:

Function CharToUnicode(strChar As String)

    Dim lngUnicode As Long

    lngUnicode = AscW(strChar)

    If lngUnicode < 0 Then
        lngUnicode = 65536 + lngUnicode
    End If

    CharToUnicode = lngUnicode

End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜