从文件中读取内容
NSString *contentPath = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"rtf"];
NSData *databuffer;
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:contentPath];
if (file == nil)
NSLog(@"Failed to open file");
databuffer = [file readDataToEndOfFile];
[file closeFile];
NSString *contentText =[[NSString alloc] initWithData:databuffer encoding:NSUTF8StringEncoding];
debugLog(@"%@",contentText);
[textView setText:contentText];
[contentText release];
//[textView setText:[bookObj commentary]];
[self.view addSubview:textView];
输出:
i\ansicpg1252\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\ql\qnatural\f0\fs24 \cf0 流是编程中的基本抽象:从一个点串行传输到另一个点的一系列位。 Cocoa 提供了三个类来表示流并方便它们在程序中的使用:NSStream、NSInputStream 和 NSOutputStream。通过这些类的实例,您可以从文件和应用程序内存中读取数据,并向其中写入数据。您还可以在基于套接字的情况下使用这些对象
如何过滤那些粗体数据..???
NSString *contentPath = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"rtf"];
NSData *databuffer;
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:contentPath];
if (file == nil)
NSLog(@"Failed to open file");
databuffer = [file readDataToEndOfFile];
[file closeFile];
NSString *contentText =[[NSString alloc] initWithData:databuffer encoding:NSUTF8StringEncoding];
debugLog(@"%@",contentText);
[textView setText:contentText];
[contentText release];
//[textView setText:[bookObj commentary]];
[self.view addSubview:textView];
Output:
i\ansicpg1252\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\ql\qnatural\f0\fs24 \cf0 A stream is a fundamental abstraction in programming: a sequence of bits transmitted serially from one point to another point. Cocoa provides three classes to represent streams and facilitate their use in your programs: NSStream, NSInputStream, and NSOutputStream. With the instances of these classes you can read data from, and write data to, files and application memory. You can also use these objects in socket-based
How to filter those bold data..???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试将 RTF 文本加载到纯字符串中。请改用 NSAttributedString 或将文件转换为纯文本。
You are trying to load RTF text into a plain string. Use NSAttributedString instead or convert your file to plain text.
我不知道您是否也打算编辑此文本或只是显示它,但我知道的唯一可行的方法是使用
UIWebView
I dont know if you were planning to edit this text as well or just display it but the only workable way I know is to use a
UIWebView