Alternative of ChrW function

2019-07-27 09:31发布

Is there any alternative function/solution of the ChrW() which accepts value not in range is -32768–65535 like for character code 􀂇 which leads to "

1条回答
贪生不怕死
2楼-- · 2019-07-27 10:03
' https://en.wikipedia.org/wiki/UTF-16#Description
function Utf16Encode(byval unicode_code_point)
    if (unicode_code_point >= 0 and unicode_code_point <= &hD7FF&) or (unicode_code_point >= &hE000& and unicode_code_point <= &hFFFF&) Then
        Utf16Encode = ChrW(unicode_code_point)
    else    
        unicode_code_point = unicode_code_point - &h10000&
        Utf16Encode = ChrW(&hD800 Or (unicode_code_point \ &h400&)) & ChrW(&hDC00 Or (unicode_code_point And &h3FF&))
    end if
end function
For Each match In matches
    'For each unicode match, replace the whole match, with the ChrW of the digits.
    sText = Replace(sText, match.Value, Utf16Encode(CLng(match.SubMatches(0))))
Next
查看更多
登录 后发表回答