如何解决如何用 JavaScript 中的相应字母替换 Unicode 字母表情符号?
我有一个字符串,例如:“? c?ding question”。
我想将“?”、“?”和所有 Unicode 字母表情符号替换为相应的字母,如“a”、“o”等。
*注意:不确定这是否有帮助,但我相信 Unicode 字母表情符号被称为区域指示符。
解决方法
感谢 ktp 的指导,这是我最终找到的解决方案。它可能不是最有效的,但它是我目前能想到的最好的。接受反馈。
//Loop through each character of the text
for (let i = 0; i < text.length; i++) {
//Check if the character is a emoji
if (text.charCodeAt(i) >= 255)
//Check if the character is ? or between ?
if (text.codePointAt(i) >= 127462 && text.codePointAt(i) <= 127487)
//Set the text equal to text with the emoji replaced as a lowercase letter equivalent
text =
text.substr(0,i) +
String.fromCodePoint(text.codePointAt(i) - 127365) +
text.substr(i + 2);
}
,
这与您要查找的内容相似吗?:
let char = '?';
let cp = char.codePointAt(0);
let newChar = String.fromCodePoint(cp % 256);
console.log(newChar);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。