簡體   English   中英

如何將 unicode 點轉換為表情符號 || 符號 || 特點

[英]How to convert unicode point to Emoji || Symbol || Character

我想將 Unicode 代碼點符號(如“U+1F1FA U+1F1F8”)轉換為“”。

在 javaScript 中,到目前為止我嘗試過的是

String.fromCharCode(parseInt("U+1F1FA", 16));

但這不起作用。

您可以將十六進制代碼包裝在大括號中,如下所示:

console.log('\u{1f1fa}\u{1f1f8}')

您可以使用 static 方法String.fromCodePoint()來實現此目的。

 const us = String.fromCodePoint('0x1F1FA', '0x1F1F8'); console.log(us);

非常感謝以上答案。 我提供了一種將 unicode 符號轉換為表情符號的方法。

        function unicodeToChar(text:string) {
            const splited = text.split(" ")
            let str = ""
            for(let i = 0;i < splited.length;i++){
                splited[i] = splited[i].replace('U','0')
                splited[i] = splited[i].replace('+','x')
                str += String.fromCodePoint(parseInt(splited[i],16))
            }
            return str
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM