使用NSScanner在if语句中搜索字符串?

时间:2011-12-14 19:38:02

标签: iphone objective-c ios xcode nsscanner

是否可以使用ifNSScanner语句中搜索字符串?

我想搜索一个页面的html然后是否有某段代码,做一些事情,如果没有,做其他事情......

谢谢!

1 个答案:

答案 0 :(得分:3)

您无需使用NSScanner。只需在html中搜索一个子字符串为NSString。像这样:

NSString *html = [webView stringByEvaluatingJavaScriptFromString: 
                                         @"document.body.innerHTML"];

if ([html rangeOfString:@"some code here"].location!=NSNotFound) {
    //it exists in the web view
}