title: HTML entity encoding (convert '<' to '&lt;') on iPhone in objective-c
body: <p>I'm developing an application for the iPhone that has inApp-mail sending capabilities. So far so good, but now I want to avoid html-injections as some parts of the mail are user-generated texts.</p>
  
  <p>Basically I search for something like this:</p>
  
  <pre><code>// inits
  NSString *sourceString = [NSString stringWithString:@"Hello world! Grüße dich Welt &lt;-- This is in German."];
  
  //                                          -----   THAT'S WHAT I'M LOOKING FOR
  // pseudo-code                              |
  //                                          V
  NSString *htmlEncodedString = [sourceString htmlEncode];
  
  // log
  NSLog(@"source string: %@", sourceString);
  NSLog(@"encoded string: %@", htmlEncodedString);
  </code></pre>
  
  <p><strong><em>Expected output</em></strong> <br>
  <code>source string: Hello world! Grüße dich Welt &lt;-- This is in German.</code><br>
  <code>encoded string: Hello world! Gr&amp;#252;&amp;#223;e dich Welt &amp;lt;-- This is in German.</code>
  <br>
  <br>
  I already googled and looked through several of SO's questions and answers, but all of them seem to be related to <em>URL-encoding</em> and that's not what I really need (I tried <code>stringByAddingPercentEscapesUsingEncoding</code> with no luck - it creates %C3%BC out of an 'ü' that should be an &#252;).</p>
  
  <p>A code sample would be really great (correcting mine?)...</p>
  
  <p>--<br>
  Thanks in advance,<br>
  Markus</p>