I have an instance of NSData
containing attributed text (NSAttributedString
) originating from an NSTextView
. I want to convert the attributed string to a plain string (NSString
) 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).
What would be the best way to do this?
EDIT:
Out of curiosity I examined the result of:
[[[self textView] textStorage] words]
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"):
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 (
28L,
56L,
84L,
112L,
140L,
168L,
196L,
224L,
252L,
280L,
308L,
336L
), DefaultTabInterval 0, Blocks (null), Lists (null),
BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0.05,
HeaderLevel 0"; }
NSSubTextStorage is probably a private class as I could not find any documentation for it. It also retains all formatting.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…