문제

I want to know how to convert the emoji to hex value.That is for the smiley having 'SMILING FACE WITH OPEN MOUTH AND SMILING EYES' (smiley corresponds to :) ) I should get "1F604"

도움이 되었습니까?

해결책

Is this what you are looking for?

NSString *smiley = @"😄";

NSData *data = [smiley dataUsingEncoding:NSUTF32LittleEndianStringEncoding];
uint32_t unicode;
[data getBytes:&unicode length:sizeof(unicode)];
NSLog(@"%x", unicode);
// Output: 1f604

Reverse direction:

uint32_t unicode = 0x1f604;

NSString *smiley = [[NSString alloc] initWithBytes:&unicode length:sizeof(unicode) encoding:NSUTF32LittleEndianStringEncoding];
NSLog(@"%@", smiley);
// Output: 😄

Remark: Both code examples assume that integers are stored in little-endian byte order (which is the case for all current platforms running OS X or iOS).

다른 팁

Swift Version

let smiley = "😊"

let uni = smiley.unicodeScalars // Unicode scalar values of the string
let unicode = uni[uni.startIndex].value // First element as an UInt32

println(String(unicode, radix: 16, uppercase: true))
// Output: 1F60A
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top