如何在 .txt 文件中搜索 NSScanner 的字符串?
可能的重复:
使用 NSScanner 查找短语的下一个匹配
我目前有下面的代码从 UIWebView 获取特定的代码:
NSURL *requestTimetableURL = [NSURL URLWithString:@"http://www.dhsb.org/index.phtml?d=201435"];
NSLog(@"Loaded Timetable");
NSError *error;
NSString *page = [NSString stringWithContentsOfURL:requestTimetableURL
encoding:NSASCIIStringEncoding
error:&error];
[webView loadHTMLString:page baseURL:requestTimetableURL];
NSString* Period1;
NSScanner *htmlScanner = [NSScanner scannerWithString:page];
[htmlScanner scanUpToString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
[htmlScanner scanString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
[htmlScanner scanUpToString:@"</FONT>" intoString:&Period1];
如何扫描 .txt 文件(包含上面的字符串)以获取代码?
EG [htmlScanner scanUpToString:teststring intoString:NULL];
(teststring 是 .txt 文件)
谢谢!
Possible Duplicate:
Find next match of a phrase with NSScanner
I currently have the following code to get a certain piece of code from the UIWebView:
NSURL *requestTimetableURL = [NSURL URLWithString:@"http://www.dhsb.org/index.phtml?d=201435"];
NSLog(@"Loaded Timetable");
NSError *error;
NSString *page = [NSString stringWithContentsOfURL:requestTimetableURL
encoding:NSASCIIStringEncoding
error:&error];
[webView loadHTMLString:page baseURL:requestTimetableURL];
NSString* Period1;
NSScanner *htmlScanner = [NSScanner scannerWithString:page];
[htmlScanner scanUpToString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
[htmlScanner scanString:@"<P align=center><STRONG><FONT color=#c00000>" intoString:NULL];
[htmlScanner scanUpToString:@"</FONT>" intoString:&Period1];
How can I scan a .txt file (which contains the string like above) for the code?
E.G. [htmlScanner scanUpToString:teststring intoString:NULL];
(teststring being the .txt file)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSString *myText = [NSString stringWithContentsOfFile:path];
您可以在此处查看示例:
http://iphoneincubator.com /blog/data-management/how-to-read-a-file-from-your-application-bundle
如果您不想从包(您的应用程序)中读取数据,而是从文档目录中读取数据,请使用:
NSString *myText = [NSString stringWithContentsOfFile:path];
You can see examples here:
http://iphoneincubator.com/blog/data-management/how-to-read-a-file-from-your-application-bundle
if you don't want to read from your bundle (your app) but from your documents dir, use: