Next / Previous / Contents / TCC Help System / NM Tech homepage

32. Scan.find(): Search for a constant string

logscan.py
# - - -   S c a n . f i n d

    def find ( self, s ):
        '''Does string s occur at or after the current position?
        '''

We use the standard str.find method to do the searching. This method returns -1 if the string is not found.

logscan.py
        #-- 1 --
        # [ if s is found at or after self.line[self.pos:] ->
        #     result  :=  position of the first match relative
        #                 to self.line
        #   else ->
        #     result  :=  -1 ]
        result = self.line.find ( s, self.pos )

        #-- 2 --
        if result < 0:
            return None
        else:
            return result