Alternative of ChrW function

后端 未结 1 1508
北恋
北恋 2020-12-18 15:03

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

相关标签:
1条回答
  • 2020-12-18 15:42
    ' 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
    
    0 讨论(0)
提交回复
热议问题