我试图从我的应用包中读取文本文件的内容是:
1234567890
但是当我在读完之后显示字符串时这样:
{\ RTF1 \ ANSI \ ansicpg1252 \ cocoartf1038 \ cocoasubrtf320 {\ fonttbl \ f0 \ fswiss \ fcharset0 Helvetica;} {\ colortbl; \ red255 \ green255 \ blue255;} \ PARD \ tx566 \ tx1133 \ tx1700 \ tx2267 \ tx2834 \ tx3401 \ tx3968 \ tx4535 \ tx5102 \ tx5669 \ tx6236 \ tx6803 \ QL \ qnatural \ pardirnatural
\ f0 \ fs24 \ cf0 1234567890 \ \ \ \ \ \ \ \ }
我怎样才能得到确切的字符串而不是垃圾?我的代码是这样的:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"pankaj" ofType:@"rtf"];
if (filePath) {
NSString *myText = [NSString stringWithContentsOfFile:filePath];
if (myText) {
NSLog(@"%@",myText);
}
}
好的答案将得到赞赏
答案 0 :(得分:1)
您正在以纯文本格式阅读富文本格式的资源(rtf)。您获得的字符串是该rtf资源的纯文本表示。
为什么不将文件添加为纯文本文件?