Question

In iOS I'd like to perform some specific functions if the user's [NSLocale currentLocale] does not use Arabic Numerals (i.e. not 0123456789). How can I check for this condition?

Was it helpful?

Solution

Unfortunately there is no direct attribute to check, but the following code will check it:

NSCharacterSet *nSet = [NSCharacterSet characterSetWithCharactersInString:@"1234567890"];
NSNumberFormatter *numFmt = [[NSNumberFormatter alloc] init];
NSDecimalNumber *value = [NSDecimalNumber decimalNumberWithString:@"1234567890"];
NSCharacterSet *fSet = [NSCharacterSet characterSetWithCharactersInString:[numFmt stringFromNumber:value]];
if([fSet isSupersetOfSet:nSet]==NO){
    NSLog(@"No arabic digits");
}

The check is done via a set of the digits (nSet) against the locale aware formatter of the current locale (numFmt). The value is used to format a number of all digits, which could be reduced to less digits than 1 to 0. However this might serve as an example of other detections as well. Please note that using a separator or thousand grouping character will not break the detection because superset is being used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top