简体   繁体   中英

How to convert unicode point to Emoji || Symbol || Character

I want to convert Unicode Code Points Notation like "U+1F1FA U+1F1F8" to "".

In javaScript, what I have tried so far is

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

But this doesn't work.

You can wrap the hex code in braces like this:

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

You can use the static method String.fromCodePoint() to achieve this.

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

Thanks a lot for above answers. I came with a method to convert the unicode notations to Emoji.

        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
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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