Page 87 -
P. 87

searching for substrings


           Searching is complex


          You already know how to find a substring, so you could run through the
           entire web page and check each two characters to see if they match >$,
           like this:



                   We could search through the
                   whole string for “>$", looking
                    at 2 characters at a time.




























                                                 We’ve found “>$"!
                                                                               So these next 4
                                                                               characters must be
                                                                               the price, right?

          You could do it this way... but should you?
           There’s a lot to worry about. Which two characters are you currently
           comparing? Where in the string are you right now? What if “>$” isn’t
           found? Searching for substrings in strings is a little more complex than it
           first appears...

           But if you don’t want to write code to search the
           string, what else could you do?





           52    Chapter 2
   82   83   84   85   86   87   88   89   90   91   92