1

I am trying to convert an emoji to an NSString. I previously asked a question on how to do the opposite (convert an NSString to a unicode) at NSString to Emoji Unicode. I thought perhaps it would be best to ask this as a new question here.

How can I convert an NSString containing an emoji () to an NSString containing a unicode in this format (U0001F603)?

This question is basically the reverse engineering of the solution from the previous page. The catch is the project does not use the \ue415 format, but rather the U0001F603 format.

Edited per comment:
2014-07-11 11:37:19.448 emoticon[******] unicode:

unicode = [NSString stringWithFormat:@"%@\\UFE0E", unicode];

2014-07-11 11:37:19.449 emoticon[******] unicode: \UFE0E

SECOND COMMENT RESPONSE I'm not entirely sure if I follow what you mean by I didn't add the first line of code. I hope I haven't been unclear. To try and be more specific on what I would like, I logged your code in, and then logged what I wish to get:

NSString *first = @"";
NSString *second = @"\\UFE0E";
NSString *third = @"U0001F603\\UFE0E";

2014-07-11 12:00:45.815 emoticon[******] first: , second: \UFE0E, third: U0001F603\UFE0E
2014-07-11 12:00:45.816 emoticon[******] desiredString: U0001F603

My hope is to produce the desiredString by converting the emoji to the desired string.

THIRD COMMENT RESPONSE enter image description here

Community
  • 1
  • 1
Jeremy H
  • 452
  • 7
  • 20
  • Oh! Wait! Is `%@\ ` the emoji code for that icon, and you're generating that icon based on that? (Am away from my Mac at the moment, that's why I can't try it myself and asking instead). – Neeku Jul 11 '14 at 16:47
  • Yes, the %@ contains the actual emoji in it. It is the that I am trying to convert into a raw NSString. The variable unicode is of NSString. I would like for the conversation to allow the variable unicode to be logged as U0001F603 rather than . – Jeremy H Jul 11 '14 at 16:52
  • Ok. I get you now. Let me think about it... – Neeku Jul 11 '14 at 16:53
  • You're adding two back-slashes between the character codes. Add only one. – Neeku Jul 11 '14 at 17:06
  • It will not allow me to use one \ unless I am using a unicode such as \ue415. Attaching a screenshot up above. I'm really sorry for the trouble and lack of any clarity on my part. – Jeremy H Jul 11 '14 at 17:10
  • Hmm... I should check this myself. Hopefully I'll have some time to do so tomorrow. (: – Neeku Jul 12 '14 at 02:03
  • See! I edited my answer below, the issue was the formating of the character and adding the four zeros after `U` fixed that error, however this is not changing anything. Can you just provide an example input and output for what you want? – Neeku Jul 12 '14 at 22:00
  • 1
    possible duplicate of [iOS 5: How to convert an Emoji to a unicode character?](http://stackoverflow.com/questions/8635393/ios-5-how-to-convert-an-emoji-to-a-unicode-character) – durron597 Sep 04 '15 at 13:41

2 Answers2

2

What you need is using the escape character \U0000FE0E to the end of all Unicode characters to make it skip the emoji and display the proper Unicode character.

Here's the code:

@""        //This shows the colorful emoji icon.
@"\U0000FE0E"  //This shows the good old Unicode character.

You can also add it to the character code:

@"U0001F603\U0000FE0E"
Neeku
  • 3,646
  • 8
  • 33
  • 43
  • Thanks, but at this point I am already able to make the emoji. What I am trying to do is code it so an existing emoji is converted back into a raw NSString. – Jeremy H Jul 11 '14 at 16:30
  • That's just what I explained. If you add `\UFE0E` to your existing emoji, it'll revert it to a Unicode char. – Neeku Jul 11 '14 at 16:32
  • Where do you add this? Edit your answer and show the code there, please. – Neeku Jul 11 '14 at 16:38
  • See my comment above. I think I'm confused now! Also I think you haven't added the first line of your code. – Neeku Jul 11 '14 at 16:49
  • Updating question again with new code. Man this is getting ugly haha. I'll clean it up nicely if we can figure the answer out. – Jeremy H Jul 11 '14 at 17:01
  • Still seems to not be working in the way we would expect. Using NSLog(@"%@\U0000FE0E", unicode); produces the emoji ︎ rather than a string. – Jeremy H Jul 14 '14 at 16:49
  • Yeah, exactly. However I think I'm missing something from your question. That code would skip the colorful emoji and will display the unicode alternative, like the black and white icon, where you want to get the string behind it. However I imagine you have the string in the other format like `ue415`, don't you? – Neeku Jul 14 '14 at 16:51
  • I have actually found another work around for the issue (by "re-architecting" the backend). I know this isn't the StackOverflow way, but perhaps we should drop this question. You have been nothing sort of super amazing though, so for (i = 0; i < awesome; i ++) { thank you! } – Jeremy H Jul 14 '14 at 20:32
  • Jeremy , can you point me to your solution? I am having the same problem. Thanks! – Kong Hantrakool Sep 07 '14 at 16:32
-1

Here is a "pseudo-code" (JavaScript, you can run it in your browser's console) ..for opposite-direction.

String.fromCharCode(
((0x1F603 - 0x10000) >> 10) | 0xD800
,
((0x1F603 - 0x10000) % 0x400) | 0xDC00
)

=>>""

Just reverse the bytewise operations, and zero-pad it.


If you are a programmer it should be more than easy for you.


..give a man a fish...



source: JavaScript Ninja - Easy Unicode Emoji Generator