且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将NSAttributedString转换为纯文本

更新时间:2023-02-03 08:29:13

如果我对您的理解正确,则您有一个 NSData ,例如 data ,其中包含编码的 NSAttributedString 。要逆转该过程,请执行以下操作:

If I understand you correctly you have an NSData, say data, containing an encoded NSAttributedString. To reverse the process:

NSAttributedString *nas = [[NSAttributedString alloc] initWithData:data
                                                           options:nil
                                                documentAttributes:NULL
                                                             error:NULL];

然后获取没有属性的纯文本,然后执行以下操作:

and to get the plain text without attributes you then do:

NSString *str = [nas string];