title: Remove HTML Tags from an NSString on the iPhone
body: <p>There are a couple of different ways to remove <code>HTML tags</code> from an <code>NSString</code> in <code>Cocoa</code>.</p>
  
  <p><a href="http://cocoa.karelia.com/Foundation_Categories/NSString/_Flatten__a_string_.m" rel="noreferrer">One way</a> is to render the string into an <code>NSAttributedString</code> and then grab the rendered text.</p>
  
  <p><a href="http://sugarmaplesoftware.com/25/strip-html-tags/#comment-71" rel="noreferrer">Another way</a> is to use <code>NSXMLDocument's</code> -<code>objectByApplyingXSLTString</code> method to apply an <code>XSLT</code> transform that does it.</p>
  
  <p>Unfortunately, the iPhone doesn't support <code>NSAttributedString</code> or <code>NSXMLDocument</code>. There are too many edge cases and malformed <code>HTML</code> documents for me to feel comfortable using regex or <code>NSScanner</code>. Does anyone have a solution to this?</p>
  
  <p>One suggestion has been to simply look for opening and closing tag characters, this method won't work except for very trivial cases. </p>
  
  <p>For example these cases (from the Perl Cookbook chapter on the same subject) would break this method:</p>
  
  <pre><code>&lt;IMG SRC = "foo.gif" ALT = "A &gt; B"&gt;
  
  &lt;!-- &lt;A comment&gt; --&gt;
  
  &lt;script&gt;if (a&lt;b &amp;&amp; a&gt;c)&lt;/script&gt;
  
  &lt;![INCLUDE CDATA [ &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ]]&gt;
  </code></pre>