在IOS中读取RTFD数据 [英] Read RTFD data in IOS
本文介绍了在IOS中读取RTFD数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要读取IOS的NSData对象中的RTFD数据。在MacOSX中,我只是使用NSAttributedString读取它们,但现在我知道IOS不支持它们。
I have RTFD data in NSData objects in IOS that I need to read. In MacOSX I just used to read them with NSAttributedString, but now I know that they are not supported in IOS.
attribString = [[NSAttributedString alloc] initWithRTFD:note documentAttributes:&dict];
有什么方法可以在IOS中仅读取RTFD数据的文本吗?
Is there any way to read only the text of the RTFD data in IOS?
推荐答案
iOS中的rtfd类似于目录。如果只想获取文本部分,则可以尝试:
The rtfd in iOS is something like as a directory. If you only want to get the text part, you can try:
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);
希望它能有所帮助。
这篇关于在IOS中读取RTFD数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文