1
我正在使用函數String.fromCharCode(十進制值),並將十進制值傳遞給它。JavaScript中的String.fromCharCode(十進制值)是否也支持擴展字符
其在英文字符方面的工作很好,但是當我試圖解碼日文字符時,它給了我一些仲裁字符。
誰能告訴我嗎String.fromCharCode(十進制值)支持擴展字符。
我正在使用函數String.fromCharCode(十進制值),並將十進制值傳遞給它。JavaScript中的String.fromCharCode(十進制值)是否也支持擴展字符
其在英文字符方面的工作很好,但是當我試圖解碼日文字符時,它給了我一些仲裁字符。
誰能告訴我嗎String.fromCharCode(十進制值)支持擴展字符。
不,它不支持使用兩個代理項的字符。 MDC有一個實用功能,旨在處理此問題:
// String.fromCharCode() alone cannot get the character at such a high code point
// The following, on the other hand, can return a 4-byte character as well as the
// usual 2-byte ones (i.e., it can return a single character which actually has
// a string length of 2 instead of 1!)
alert(fixedFromCharCode(0x2F804)); // or 194564 in decimal
function fixedFromCharCode (codePt) {
if (codePt > 0xFFFF) {
codePt -= 0x10000;
return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 +
(codePt & 0x3FF));
}
else {
return String.fromCharCode(codePt);
}
}