Read RTFD data in IOS

心已入冬 提交于 2019-12-23 05:39:21

问题


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];

Is there any way to read only the text of the RTFD data in IOS?


回答1:


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);

Hope it can help.



来源:https://stackoverflow.com/questions/6902313/read-rtfd-data-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!