如何在java中获取表情符号代码?

时间:2021-09-10 06:24:59

I want java escape code for all emojis. For e.g if anyone put up ???? smiley then I want its java code which is "\ud83d\ude05" . Anybody knows how to convert emojis to its java code as I said in above e.g ?

我想要所有emojis的java转义码。例如,如果有人提出????笑脸,那么我想要它的java代码是“\ ud83d \ ude05”。有人知道如何将emojis转换为java代码,如上所述,例如?

2 个解决方案

#1


1  

It's not too hard to write one:

写一个并不难:

import java.util.stream.Collectors;

class StringRepr {
    private static String escapeChar(int c) {
        if (c <= 0x7f) {
            return Character.toString((char) c);
        } else {
            return "\\u" + String.format("%04x", c);
        }
    }

    public static String escape(String s) {
        return s.chars().mapToObj(c -> escapeChar(c)).collect(Collectors.joining());
    }

    public static void main (String[] args) {
        System.out.println(escape("????"));
    }
}

#2


0  

"\\ud83d\\ude05" You can try this ,"\"this element hava a special sense

“\\ ud83d \\ ude05”你可以尝试这个,“\”这个元素具有特殊意义

#1


1  

It's not too hard to write one:

写一个并不难:

import java.util.stream.Collectors;

class StringRepr {
    private static String escapeChar(int c) {
        if (c <= 0x7f) {
            return Character.toString((char) c);
        } else {
            return "\\u" + String.format("%04x", c);
        }
    }

    public static String escape(String s) {
        return s.chars().mapToObj(c -> escapeChar(c)).collect(Collectors.joining());
    }

    public static void main (String[] args) {
        System.out.println(escape("????"));
    }
}

#2


0  

"\\ud83d\\ude05" You can try this ,"\"this element hava a special sense

“\\ ud83d \\ ude05”你可以尝试这个,“\”这个元素具有特殊意义