-2

Is it possible to search for a string in an if statement with an NSScanner?

I wanted to search through the html of a page and then if there is a certain piece of code, do something and if not, do something else...

Thanks!

Kevin
  • 53,822
  • 15
  • 101
  • 132
pixelbitlabs
  • 1,934
  • 6
  • 36
  • 65

1 Answers1

3

You don't need to use a NSScanner. Just search for a substring in the html as a NSString. Like so:

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

if ([html rangeOfString:@"some code here"].location!=NSNotFound) {
    //it exists in the web view
}
sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
  • I don't understand what to put in place of "incomingtext" because all I have is a UIWebView and a website loaded within that, nothing else... – pixelbitlabs Dec 14 '11 at 19:49
  • I updated the example for you. You're going to use javascript to extract the html from the web view, and stuff that into a string. Then you search that NSString for the search term that I have put in as `some code here`. Let me know if it doesn't work for you, because I actually haven't tested it. :) – sudo rm -rf Dec 14 '11 at 21:30
  • thanks for that - you've been really helpful! :-) Would you be able to look at this question as nobody has properly answered it? http://stackoverflow.com/questions/8508311/nsscanner-working-on-wifi-but-not-3g – pixelbitlabs Dec 15 '11 at 17:38