【问题标题】:Read RTFD data in IOS在 IOS 中读取 RTFD 数据
【发布时间】:2011-08-01 17:49:28
【问题描述】:

我在 IOS 的 NSData 对象中有需要读取的 RTFD 数据。在 MacOSX 中我只是用 NSAttributedString 读取它们,但现在我知道它们在 IOS 中不受支持。

 attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict];

有什么方法可以在IOS中只读取RTFD数据的文本吗?

【问题讨论】:

  • 虽然不支持 initWithRTFD:documentAttributes:,但从 iOS 3.2 开始支持 NSAttributedString 类!

标签: iphone cocoa-touch uitextview nsdata nsattributedstring


【解决方案1】:

iOS 中的 rtfd 类似于目录。如果只想获取文本部分,可以试试:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"photo" ofType:@"rtfd"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *content = [fileManager contentsOfDirectoryAtPath:filePath error:nil];
NSString *textFilePath = [filePath stringByAppendingPathComponent:@"TXT.rtf"];//you can get the path component from the content; usually it is TXT.rtf
NSError *error = nil;
NSString *pureText = [[NSString alloc] initWithContentsOfFile:textFilePath encoding:NSASCIIStringEncoding error:&error];
NSLog(@"pureText:\n%@",pureText);

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2017-07-26
    相关资源
    最近更新 更多