Reputation: 106
๐ how can I convert emojis like this to text? I mean to convert a happy face to the words "happy" and so on. Using Java, how can I achieve this?
Upvotes: 2
Views: 14796
Reputation: 2444
You may use emoji4j library.
String text = "A ๐ฑ, ๐ถ and a ๐ญ became friendsโค๏ธ. For ๐ถ's birthday party, they all had ๐s, ๐s, ๐ชs and ๐ฐ.";
EmojiUtils.shortCodify(text); //returns A :cat:, :dog: and a :mouse: became friends:heart:. For :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.
Upvotes: 11
Reputation: 881113
Since that emoji is simply a standard Unicode code point (U+1F601
, see here), probably the best way is to set up a map which translates them into strings.
By way of example, here's a piece of code that creates a string-to-string map to allow you to look up and translate that exact code point:
import java.util.HashMap;
import java.util.Map;
class Xyzzy {
public static Map<String,String> xlat = new HashMap<String, String>();
public static void main (String[] args) {
xlat.put("\uD83D\uDE01", "happy");
System.out.println(xlat.get("\uD83D\uDE01"));
}
}
You can add as many code points to the map as you wish, and use Map.get()
to extract the equivalent text for any of them.
Upvotes: 1