Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fajhetti

macrumors newbie
Original poster
Jul 20, 2008
7
0
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.
 
You inverted the set, so rangeOfCharacterFromSet: is going to match everything except those characters you specified.
 
Thank you. I hate when I do stupid stuff and go so far as to post and look like a real idiot. Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.