title: Transform an NSAttributedString to plain text
body: <p>I have an instance of <code>NSData</code> containing attributed text (<code>NSAttributedString</code>) originating from an <code>NSTextView</code>. I want to convert the attributed string to a plain string (<code>NSString</code>) without any formatting to do some text analysis (at the moment of conversion I do not have access to the originating NSTextView nor its NSTextStorage instance).</p>
  
  <p>What would be the best way to do this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Out of curiosity I examined the result of:</p>
  
  <pre><code>[[[self textView] textStorage] words]
  </code></pre>
  
  <p>which appeared to be a handy thing for doing some text analysis. The resulting array contains instances of NSSubTextStorage (example below of the word "Eastern"):</p>
  
  <blockquote>
    <p>Eastern{
        NSFont = "\"LucidaGrande 11.00 pt. P [] (0x7ffcaae08330) fobj=0x10a8472d0, spc=3.48\"";
        NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0,
    FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0,
    LineBreakMode 0, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n<br>
    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n<br>
    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null),
    BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0.05,
    HeaderLevel 0"; }</p>
  </blockquote>
  
  <p>NSSubTextStorage is probably a private class as I could not find any documentation for it. It also retains all formatting.</p>