开发者

How to determine if an NSString is latin based?

开发者 https://www.devze.com 2023-02-19 15:18 出处:网络
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:

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

精彩评论

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