【问题标题】:Search for a string in an if statement with an NSScanner?使用 NSScanner 在 if 语句中搜索字符串?
【发布时间】:2011-12-14 19:38:02
【问题描述】:

是否可以在if 语句中搜索带有NSScanner 的字符串?

我想通过一个页面的 html 进行搜索,然后如果有某段代码,就做某事,如果没有,就做其他事情……

谢谢!

【问题讨论】:

    标签: iphone objective-c ios xcode nsscanner


    【解决方案1】:

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

    NSString *html = [webView stringByEvaluatingJavaScriptFromString: 
                                             @"document.body.innerHTML"];
    
    if ([html rangeOfString:@"some code here"].location!=NSNotFound) {
        //it exists in the web view
    }
    

    【讨论】:

    • 我不明白用什么来代替“incomingtext”,因为我只有一个 UIWebView 和一个加载在其中的网站,没有别的......
    • 我为您更新了示例。您将使用 javascript 从 web 视图中提取 html,并将其填充到字符串中。然后你在 NSString 中搜索我输入为 some code here 的搜索词。如果它不适合你,请告诉我,因为我实际上还没有测试过它。 :)
    • 谢谢你 - 你真的很有帮助! :-) 你能看看这个问题,因为没有人正确回答吗? stackoverflow.com/questions/8508311/…
    猜你喜欢
    • 1970-01-01
    • 2014-06-18
    • 2012-11-09
    • 2011-12-05
    • 2013-12-13
    • 1970-01-01
    • 2014-03-02
    • 2018-08-09
    • 1970-01-01
    相关资源
    最近更新 更多