gpt4 book ai didi

iphone - 从文件中读取内容

转载 作者:行者123 更新时间:2023-12-03 21:22:37 25 4
gpt4 key购买 nike

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

如何过滤那些粗体数据..???

最佳答案

您正在尝试将 RTF 文本加载到纯字符串中。请改用 NSAttributedString 或将文件转换为纯文本。

关于iphone - 从文件中读取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3369855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com