0

I am building an android app, which includes a feature where a user can enter a string and emoticons (if he wants to). For example:

Happy Halloween! :D :D :D

I want to get the UTF-8 code of the emoticons entered by the user, so in the background it looks like:

Happy Halloween! U+1F601 U+1F601 U+1F601

Following is my code but it isn't working:

    class emoticons
   {
  public static void main(String[] args)
   {
    Scanner emo = new Scanner(System.in);
    System.out.println(emo.nextLine());   
    
    Pattern pattern = Pattern.compile("(<U\\+\\w+?>)");
    Matcher matcher = pattern.matcher(s);
    List<String> matchList = new ArrayList<String>();

    while (matcher.find()) 
    {
        matchList.add(matcher.group());
    }

    for(int i=0;i<matchList.size();i++){
        System.out.println(matchList.get(i));
    }
    

So basically, i just want to get the UTF code of the emoticons pressed by the user.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    If that is what your user enters, the string does not contain emoticon characters at all. – Jongware May 10 '15 at 21:14
  • @Jongware: Why so? Is the system not going to consider it as a character or something? or will it just take only the string "happy halloweeen" and print it out? – Shivanshu Rathore May 11 '15 at 03:58
  • Instead of this `U+1F601` a TextView will recognize this `\u1F601`. However, mind that not all Unicode characters are included in the standard system font. You have to resort to some emoticon library or specifc font for that. – Phantômaxx May 11 '15 at 07:35
  • 6
    Your example string contains plain ASCII characters only. Possibly you are *mentally* translating each of the last 3 sets of `:)` to a single Unicode character ``, or your software generally translates it *for* you and you are not aware of that (thus falsely led to *believe* that `:)` ≡ ``), or your example is really bad. – Jongware May 11 '15 at 08:33

0 Answers0