How to detect space, and special characters like :, ?,`,~, etc in text of a textfield in iPhone SDK?
How to detect space, and special characters 开发者_开发知识库like :, ?,`,~, etc in text of a textfield in iPhone SDK?
Try this..
NSCharacterSet* symbols = [NSCharacterSet symbolCharacterSet];
if([symbols characterIsMember: yourCharacter]) {
//Check Your condition here
}
If you want to include many characters Use a combined NSCharacterset with NSMutableCharacterSet..
NSMutableCharacterSet *space = [NSMutableCharacterSet characterSetWithCharactersInString:@" "];
[space formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];
Use the space characterset to check the character
You could also use an instance of NSScanner
to parse your string. It is a bit more complicated than BuildSucceeded's answer but it's good to know that this exists.
Also when using NSScanner
you would have to construct the right NSCharacterSet. Look in its documentation to find out how this works.
精彩评论