问题描述
所以,我想做的是获取一个.txt或html文件,能够对其进行搜索,然后从文件中获取一段文本,将其放入字符串中,最后将其添加到textView中.
So, what I'm trying to do, is take a .txt or html file, being able to search through it, and grab a piece of text from file, place it into a string and finally adding it into a textView.
每段文本将被这样划分:
Each couple of piece of text will be divided like this:
001:002文本2
001:002 Text2
001:003文本3
001:003 Text3
002:001文本1a
002:001 Text1a
002:002文本1b
002:002 Text1b
...等等
因此,从本质上讲,您将在文本中搜索这些数字,并且仅会捕获该文本.有没有办法使用目标C并在iPhone应用程序上使用它?
So essentially you would search the text for those numbers, and it would grab the text only. Is there a way to do that using objective C and using it on a iPhone app?
推荐答案
使用
NSString *pathToDefaultPlist = [[NSBundle mainBundle] pathForResource:@"TextFile" ofType:@"text"];
加载文本文件.然后:
+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error
此函数以String形式加载文本文件.然后使用NSString函数对令牌进行划分:)
this function to load the text file in String. Then use NSString function to divide the token :)
这篇关于将.txt或html文件解析为iPhone SDK中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!