ChrW 功能的替代方案
Alternative of ChrW function
是否有 ChrW()
的任何替代 function/solution 接受不在范围内的值是 -32768–65535 就像字符代码 􀂇
导致“”。使用 ChrW()
给出错误
"Invalid procedure call or argument"
所以我想要一个替代解决方案来将字符代码转换为实际字符。
Code:
Function HTMLDecode(sText)
Dim regEx
Dim matches
Dim match
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, "&" , Chr(38))
sText = Replace(sText, " ", Chr(32))
Set regEx= New RegExp
With regEx
.Pattern = "&#(\d+);" 'Match html unicode escapes
.Global = True
End With
Set matches = regEx.Execute(sText)
'Iterate over matches
For Each match In matches
'For each unicode match, replace the whole match, with the ChrW of the digits.
sText = Replace(sText, match.Value, ChrW(match.SubMatches(0)))
Next
HTMLDecode = sText
End Function
' 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
是否有 ChrW()
的任何替代 function/solution 接受不在范围内的值是 -32768–65535 就像字符代码 􀂇
导致“”。使用 ChrW()
给出错误
"Invalid procedure call or argument"
所以我想要一个替代解决方案来将字符代码转换为实际字符。
Code:
Function HTMLDecode(sText)
Dim regEx
Dim matches
Dim match
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, "&" , Chr(38))
sText = Replace(sText, " ", Chr(32))
Set regEx= New RegExp
With regEx
.Pattern = "&#(\d+);" 'Match html unicode escapes
.Global = True
End With
Set matches = regEx.Execute(sText)
'Iterate over matches
For Each match In matches
'For each unicode match, replace the whole match, with the ChrW of the digits.
sText = Replace(sText, match.Value, ChrW(match.SubMatches(0)))
Next
HTMLDecode = sText
End Function
' 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