Character set usage
Character set usage
- Subject: Character set usage
- From: Andrew Merenbach <email@hidden>
- Date: Wed, 11 Jun 2003 13:45:45 -0700
I've found a use in one of my programs for the ExpressionEvaluator
developer example (/Developer/Examples/InterfaceBuilder/BusyPalette),
but have a question about streamlining it somewhat. It includes the
following method:
- (BOOL)_isValidNumber:(NSString *)value
{
unsigned int length;
unsigned int i;
length = [value length];
for(i=0;i<length;i++){
if (![__numbersCharSet characterIsMember:[value
characterAtIndex:i]]){
return NO;
}
}
return YES;
}
1. __numbersCharSet was defined from the string @"1234567890.,"; would
it be better (or worse) to instead simply insert [NSCharacterSet
decimalDigitCharacterSet] into the code?
2. Regardless of how __numbersCharSet is defined, would better code
than the above be:
- (BOOL)_isValidNumber:(NSString *)value {
NSCharacterSet *set = [NSCharacterSet
characterSetWithCharactersInString:value];
return [__numbersCharSet isSupersetOfSet:set];
}
(And would this apply to all scenarios in which one wishes to test the
entirety of a string for invalid characters?)
Thank you,
Andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.