rangeOfCharacterFromSet HELP Please

Discussion in 'Mac Programming' started by Fajhetti, Aug 3, 2009.

  1. Fajhetti macrumors newbie

    Joined:
    Jul 20, 2008
    #1
    I am trying to use rangeOfCharacterFromSet to make sure that a set of categories do not contain any special characters. This is how I am trying to do it:

    Code:
    NSCharacterSet * doNotWant = [[NSCharacterSet characterSetWithCharactersInString:@":/|&*<>?"] invertedSet];
    NSRange inRange;
    
    for ( Proof * info in [ProofCategoriesController arrangedObjects])
    {
    	inRange = [info.CategoryDescription rangeOfCharacterFromSet:doNotWant];
    	if (inRange.location != NSNotFound)
    			[validationitems addObject:[ValidationItem InitWithValues:@"The Gallery name cannot contain any of the following characters: \" / : * ? & < > | " button:button]];
    }
    
    
    When I step through the debugger the and print description of the variables I get :
    doNotWant
    Printing description of doNotWant:
    <CFCharacterSet Items(U+0026 U+002A U+002F U+003A U+003C U+003E U+003F U+007C)>

    Printing description of info.CategoryDescription:
    Tracy Debbie

    As you can see there are not any of those special characters, but I still hit the validation line. No matter what I put in there I get to that line. I am sure I am doing something stupid because every sample I have seen seems extremely easy, but I can not get it.

    Please Help.
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    You inverted the set, so rangeOfCharacterFromSet: is going to match everything except those characters you specified.
     
  3. Fajhetti thread starter macrumors newbie

    Joined:
    Jul 20, 2008
    #3
    Thank you. I hate when I do stupid stuff and go so far as to post and look like a real idiot. Thanks
     

Share This Page