开发者

Read RTFD data in 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];

Is there any开发者_如何学Python way to read only the text of the RTFD data in IOS?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜