开发者

How to determine if an NSString is latin based?

I'm trying to determine if a string is latin based or Japanese.

I've tried something like the following but it returns YES for Japanese strings as well:

NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet];
BOOL isAlpha = [[myStr stringByTrimmingChara开发者_高级运维ctersInSet:alphaSet] isEqualToString:@""];

A string might be a word like "café" or something like "カフェ" or "喫茶店".


Use the canBeConvertedToEncoding: method. For example:

BOOL isLatin = [myString canBeConvertedToEncoding:NSISOLatin1StringEncoding];

Available encodings are here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜