title: Calculating similarity in NSStrings
body: <p>I need to find a way of comparing <code>NSString</code>s to get a percent rating of how much two sentences match.</p>
  
  <p>For instance, how similar is the content of this sentence:</p>
  
  <pre><code>NSString *firstSentence = @"The first iPhone was released in 2007.";
  </code></pre>
  
  <p>to this sentence:</p>
  
  <pre><code>NSString *secondSentence = @"in 2007, the iphone first iphone was released";
  </code></pre>
  
  <p>I've tried to split them up into words and see how many of the words match with the total amount of words and then give a percent out of that -- but that only compares the word I choose, like</p>
  
  <pre><code>NSString *oneWord = @"ipone";
  if ([oneWord isEqualToString:@"iPhone"]) {
      matchingWords++;
  }
  </code></pre>
  
  <p>This doesn't tell me that it contains the same information -- is it just misspelled, or not?</p>
  
  <p>Another idea I had was to check the pronunciation of both words, but that would be better if <code>oneWord</code> was "ifone" and not "ipone".</p>
  
  <p>This will sort of work like a plagiarism check.</p>
  
  <p>What approach should I take?</p>