How can I get the unique characters in an NSString
?
What I'm trying to do is get all the illegal characters in an NSString
so that I can prompt the user which ones were inputted and therefore need to be removed. I start off by defining an NSCharacterSet
of legal characters, separate them with every occurrence of a legal character, and join what's left (only illegal ones) into a new NSString
. I'm now planning to get the unique characters of the new NSString
(as an array, hopefully), but I couldn't find a reference anywhere.
NSCharacterSet *legalCharacterSet = [NSCharacterSet
characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789-()&+:;,'.# "];
NSString *illegalCharactersInTitle = [[self.titleTextField.text.noWhitespace
componentsSeparatedByCharactersInSet:legalCharacterSet]
componentsJoinedByString:@""];