I have a UTF-8 encoding string that I want to display in a label.
When I set a break-point and examine the variable holding the string, all looks good. However, when I try to output to the log, or to the label, I get latin encoding.
I have tried almost every suggestion on SO and beyond, but I just cannot get the string to display properly.
Here is my code:
NSString *rawString = [NSString stringWithFormat:@"%@",m_value];
const char *utf8String = [rawString UTF8String];
NSLog (@"%@", [NSString stringWithUTF8String:utf8String]);
NSLog (@"%s", utf8String);
NSLog (@"%@", rawString);
self.resultText.text = [NSString stringWithUTF8String:utf8String];
m_value is an NSString, and in the debug window, it also displays the correct encoding.
m_value NSString * 0x006797b0 @"鄧樂愚..."
NSObject NSObject
isa Class 0x3bddd8f4
[0] Class
I am using the iOS 6.1 SDK.
Ok, if m_value
is a const char contained UTF-8 string you have to use this method:
- (id)initWithUTF8String:(const char *)bytes
NSString *correctString = [[NSString alloc] initWithUTF8String: m_value];
It's incorrect to pass const char*
to @
formatter, because @
means NSObject
, so it will be always incorrect and can lead to app crash
When I want to show khmer on label, I use font 'Hanuman.ttf'. This is code I use:
`UIFont *font = [UIFont fontWithName:@"Hanuman" size:20.0f];
self.nameLabel.text = [NSString stringWithFormat:@"%@",itemName];
self.nameLabel.font = font;`
I don't know this can help you or not , but this is what I did before !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With