How do I detect space and special characters like:,?, `, ~ Etc. In text box text in iPhone SDK?

How to detect whitespace and special characters like:,?, `, ~, Etc. in text box text in iPhone SDK?

+1


source to share


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


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







All Articles