NSCharacterSet alphanumericCharacterSet
+ (id)alphanumericCharacterSet
Return Value
A character set containing the characters in the categories Letters, Marks, and Numbers.
Discussion of [NSCharacterSet alphanumericCharacterSet]
Informally, this set is the set of all characters used as basic units of alphabets, syllabaries, ideographs, and digits.
NSCharacterSet alphanumericCharacterSet example.
NSMutableCharacterSet *_alnum = [NSMutableCharacterSet characterSetWithCharactersInString@"_"];
[_alnum formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
[_alnum formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
Example of [NSCharacterSet alphanumericCharacterSet].
NSCharacterSet *charactersToRemove =
[[ NSCharacterSet alphanumericCharacterSet ] invertedSet ];
NSString *trimmedReplacement =
[[ someString componentsSeparatedByCharactersInSet:charactersToRemove ]
componentsJoinedByString:@"" ];
[[ NSCharacterSet alphanumericCharacterSet ] invertedSet ];
NSString *trimmedReplacement =
[[ someString componentsSeparatedByCharactersInSet:charactersToRemove ]
componentsJoinedByString:@"" ];
NSCharacterSet alphanumericCharacterSet example.
@implementation NSString (alphaOnly)
- (BOOL) isAlphaNumeric
{
NSCharacterSet *unwantedCharacters =
[[NSCharacterSet alphanumericCharacterSet] invertedSet];
return ([self rangeOfCharacterFromSet:unwantedCharacters].location == NSNotFound) ? YES : NO;
}
@end
- (BOOL) isAlphaNumeric
{
NSCharacterSet *unwantedCharacters =
[[NSCharacterSet alphanumericCharacterSet] invertedSet];
return ([self rangeOfCharacterFromSet:unwantedCharacters].location == NSNotFound) ? YES : NO;
}
@end