Jeremy H
Jeremy H

Reputation: 452

Convert Unicode Emoji to NSString (Not \ue415 format)

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

Upvotes: 1

Views: 5272

Answers (2)

user257319
user257319

Reputation:

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 😁🌠🐬

Upvotes: -1

Neeku
Neeku

Reputation: 3653

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"

Upvotes: 2

Related Questions