简体   繁体   English

如何在javascript中将escpaed unicode转换为emoji表情?

[英]How to convert escpaed unicode to emoji in javascript?

From twitter feed I am getting below code. 从推特饲料我得到下面的代码。 How to convert this twitter unicode to emoji in javascript? 如何在JavaScript中将此Twitter Unicode转换为表情符号?

(&# 128079;&# 128079;&# 128079;&# 128079;)

to

👏👏👏👏 👏👏👏👏

How to show the emoji symobol using javascript? 如何使用JavaScript显示表情符号符号?

You could use the regex /&# (\\w+);/ to get each Code point to a capturing group. 您可以使用正则表达式/&# (\\w+);/将每个代码点指向捕获组。 Then use String.fromCodePoint method in the replacement function of replace to get the emojis like this: 然后在replace的替换函数中使用String.fromCodePoint方法获得如下表情符号:

 const str = '&# 128079;&# 128079;&# 128079;&# 128079;' const emojiStr = str.replace(/&# (\\w+);/g, (m, c1) => String.fromCodePoint(c1)) console.log(emojiStr) 

( Regex demo ) (正则表达式演示

If you just want to display it on the DOM, you can just remove the space ( \\s ) and set the escaped string to innerHTML 如果只想在DOM上显示它,则只需删除空格( \\s )并将转义的字符串设置为innerHTML

 const str = '&# 128079;&# 128079;&# 128079;&# 128079;' document.getElementById('display').innerHTML += str.replace(/\\s/g, '') 
 <span id='display'></span> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM