How to determine if NSString is Latin?

I am trying to determine if a string is Latin or Japanese.

I tried something like the following, but it returns YES for Japanese strings:

NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet]; BOOL isAlpha = [[myStr stringByTrimmingCharactersInSet:alphaSet] isEqualToString:@""]; 

The string may be the word "cafe" or something like "γ‚« フ γ‚§" or "ε–«θŒΆ εΊ—".

+11
objective-c iphone cocoa-touch
Mar 24 2018-11-11T00:
source share
1 answer

Use the canBeConvertedToEncoding: method. For example:

 BOOL isLatin = [myString canBeConvertedToEncoding:NSISOLatin1StringEncoding]; 

Available encodings are here .

+18
Mar 24 2018-11-11T00:
source share



All Articles