title: Understanding the Use of invertedSet method of NSCharacterSet
body: <p>So as I work my way through understanding string methods, I came across this useful class
  NSCharacterSet</p>
  
  <p>which is defined in this post quite well as being similar to a string excpet it is used for holding the char in an unordered set</p>
  
  <p><a href="https://stackoverflow.com/questions/6992433/what-is-differnce-between-nsstring-and-nscharacterset">What is differnce between NSString and NSCharacterset?</a></p>
  
  <p>So then I came across the useful method invertedSet, and it bacame a little less clear what was happening exactly. Also I a read page a fter page on it, they all sort of glossed over the basics of what was happening and jumped into advanced explainations. So if you wanted to know what this is and why we use It SIMPLY put, it was not so easy instead you get statements like this from the apple documentation: "A character set containing only characters that don’t exist in the receiver." - and how do I use this exactly???</p>
  
  <p>So here is what i understand to be the use. PLEASE provide in simple terms if I have explained this incorrectly.</p>
  
  <p>Example Use:</p>
  
  <p>Create a list of Characters in a  NSCharacterSetyou want to limit a string to contain.</p>
  
  <pre><code>NSString *validNumberChars      = @"0123456789"; //Only these are valid.
  
  //Now assign to a NSCharacter object to use for searching and comparing later
  validCharSet = [NSCharacterSet characterSetWithCharactersInString:validNumberChars ];
  
  //Now create an inverteds set OF the validCharSet. 
  NSCharacterSet *invertedValidCharSet = [validCharSet invertedSet];
  
  //Now scrub your input string of bad character, those characters not in the validCharSet
  
  NSString *scrubbedString = [inputString stringByTrimmingCharactersInSet:invertedValidCharSet];
  
  //By passing in the inverted invertedValidCharSet as the characters to trim out, then you are left with only characters that are in the original set. captured here in scrubbedString.
  </code></pre>
  
  <p>So is this how to use this feature properly, or did I miss anything?</p>
  
  <p>Thanks</p>
  
  <p>Steve</p>