strchr in objective C?
- by Brian Postow
I'm trying to write the equivalent of strchr, but with NSStrings... I've currently got this:
Boolean nsstrchr(NSString* s, char c)
{
NSString *tmps = [NSString stringWithFormat: @"%c", c];
NSCharacterSet *cSet = [NSCharacterSet characterSetWithCharactersInString: tmps];
NSRange rg = [s rangeOfCharacterFromSet: cSet];
return rg.location != NSNotFound;
}
This seems needlessly complex... Is there a way to do this (preferably, one that doesn't involve turning the NSString into a cstring which doubles the run time, or writing it myself using characterAtIndex:... Am I missing some obvious method in the NSString description?