开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜