我在 IOS 的 NSData 对象中有需要读取的 RTFD 数据。在 MacOSX 中我只是用 NSAttributedString 来读取它们,但现在我知道它们在 IOS 中不受支持。
attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict];
有什么方法可以在IOS中只读取RTFD数据的文本吗?
我在 IOS 的 NSData 对象中有需要读取的 RTFD 数据。在 MacOSX 中我只是用 NSAttributedString 来读取它们,但现在我知道它们在 IOS 中不受支持。
attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict];
有什么方法可以在IOS中只读取RTFD数据的文本吗?
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);
希望它可以提供帮助。