Converting emojis to Unicode
I am creating a cross platform communication application. I have sent emojis from iphone to iphone working correctly. but when i try to send to android from iphone it doesn't display correctly. Android library understands Unicode as U + 1F604 . While I am converting emojis to Unicode it returns a result like \ ud83d \ ude04 . I want to get the result as 1F604.
Code
NSData *data = [_txtMessage.text dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Thank you in Advance. :)
source to share
Please try the following:
Convert Emoji to unicode
NSData *data = [textView.text dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *goodValue = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
goodValue = [goodValue stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
when choosing a value from the server
NSString *goodValue = [StaticClass urlDecode:[dataDict objectForKey:@"comment_text"]];
NSData *newdata=[goodValue dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *mystring=[[NSString alloc] initWithData:newdata encoding:NSNonLossyASCIIStringEncoding];
source to share
// String to unicode
if let data = NormalString.data (using: String.Encoding.nonLossyASCII) let convertString = String.init (data: data, encoding: String.Encoding.utf8) {return convertString}
// Unicode for string
if data = UnicodeString.data (using: String.Encoding.utf8) let convertString = String.init (data: data, encoding: String.Encoding.nonLossyASCII) {return convertString}
source to share