const NSStringEncoding *enc = [NSString availableStringEncodings];
while (*enc != 0) {
NSString *name = [NSString localizedNameOfStringEncoding:*enc];
NSLog(@"%@ %d",name, *enc);
enc++;
}
Name is empty, and I'm using IOS 6, is this a bug? Or did I do anything wrong? Thanks for any help.
I tweaked your code to have
NSLog(@"%@ %d (0x%x)",name, *enc, *enc);
so we can see the NSStringEncoding in hex as well as decimal. Running you test code on the iOS 6.1 iPhone simulator I get a total of 88 different NSStringEncodings, some of which return a meaningful localizedNameOfStringEncoding, these being:
Unicode (UTF-16) 10 (0xa)
Unicode (UTF-7) -2080374528 (0x84000100)
Unicode (UTF-8) 4 (0x4)
Unicode (UTF-32) -1946156800 (0x8c000100)
Unicode (UTF-16BE) -1879047936 (0x90000100)
Unicode (UTF-16LE) -1811939072 (0x94000100)
Unicode (UTF-32BE) -1744830208 (0x98000100)
Unicode (UTF-32LE) -1677721344 (0x9c000100)
Non-lossy ASCII 7 (0x7)
Presumably there just aren't localized names for all the myriad of supported encodings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.