How do I detect space and special characters like:,?, `, ~ Etc. In text box text in iPhone SDK?
2 answers
Try it.
NSCharacterSet* symbols = [NSCharacterSet symbolCharacterSet];
if([symbols characterIsMember: yourCharacter]) {
//Check Your condition here
}
If you want to include many characters, use the concatenated NSCharacteret with NSMutableCharacterSet ..
NSMutableCharacterSet *space = [NSMutableCharacterSet characterSetWithCharactersInString:@" "];
[space formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];
Use a space character to check a character
+1
source to share
You can also use an instance NSScanner
to parse your string. It's a little more complicated than BuildSucceeded's answer, but it's good to know that it exists.
Also when using NSScanner
you will need to build the correct NSCharacterSet. Take a look in your documentation to see how it works.
+1
source to share