如果s
包含20000
且j
为Len(s)
,则以下
Dim b(1 To 8)
b() = ChrW("&H" & Mid$(s, 1, j - 4)) & ChrW("&H" & Mid$(s, j - 3))
不起作用。它返回2个字符,而U + 20000是单个字符。
答案 0 :(得分:0)
更好的代码基于此示例:http://www.vbforums.com/archive/index.php/t-526476.html
Public Function ChrU(UCode As String) As String
Dim CharCode As Long
CharCode = Val("&H00" & Right(UCode, Len(UCode) - 2))
If CharCode < 0 Then
CharCode = CharCode + 65536
End If
Dim lngChar As Long
If CharCode >= 0 Then
If CharCode < &HD800& Then
ChrU = ChrW$(CharCode)
Exit Function
ElseIf CharCode < &HDC00& Then
' UTF-16 surrogates are invalid in UTF-32
ElseIf CharCode < &HFFFF& Then
ChrU = ChrW$(CharCode)
Exit Function
ElseIf CharCode < &H10FFFF Then
lngChar = CharCode - &H10000
ChrU = ChrW$(&HD800& Or (lngChar \ 1024)) & ChrW$(&HDC00& Or (lngChar And &H3FF&))
Exit Function
End If
End If
Err.Raise 5
End Function