Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Proclip2 Library - <b> wildrat() </b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 WILDRAT() 


          The WILDRAT function will perform a search of a target string for
          the first occurrence matching another string pattern but in a right
          to left type search.  The target string is searched in a right to
          left manner looking for the first occurrence of the pattern string.
          The pattern string may contain the wildcard character (?)
          indicating a "don't care" for this position within the match.  The
          function also has the options of ignoring case during the match or
          altering the offset within the target string for the scan to begin.


      Format: 

               WILDRAT(pattern, target [,offset] [,case])


      Parameters: 

               pattern...Character string variable or constant which is the
                         string to look for in the TARGET string.  The
                         PATTERN length must be greater than zero, less that
                         32,767 and shorter than the TARGET length.  The
                         following are special cases within the pattern.

                         ? (wildcard)   Indicates to the matching process
                                        that it should ignore the character
                                        in this position, but that a
                                        character will exist in that
                                        position.  The PATTERN of "t??" will
                                        match on all of the following
                                        examples: "that", "test", "text" and
                                        "with this".  The last one will match
                                        because of the .."th t.." matches the
                                        wildcard pattern.

                         \ (literal)    Indicates to the matching process
                                        that it should take the next
                                        character in the PATTERN literally.
                                        This may be used when attempting to
                                        match on the wildcard character
                                        itself.  For instance, a pattern of
                                        "\?" will match in the phrase "Do you
                                        understand?" when the question mark
                                        is encountered.  To match on the
                                        backslash character (\) itself, just
                                        precede it with a literal flag (eg.
                                        "\\").

               target....Character string variable or constant which is the
                         string to search for the occurrence of PATTERN.  The
                         TARGET length must be greater than zero, equal to or
                         less than 32,767 and greater than the PATTERN
                         length.

              offset.. OPTIONAL .  Numeric variable or constant which is
                         the offset within the TARGET for the search to begin.
                         The default is no offset so searching will start at
                         the last character in the TARGET.  The last
                         character in the TARGET is at offset zero (0) so all
                         offsets are the actual character position in the
                         string minus one.  Think of the offset as telling
                         the function to "ignore this many characters before
                         beginning the search."  The length of the PATTERN
                         string plus this OFFSET must not exceed the length
                         of the TARGET string.

             case......  OPTIONAL .  Logical variable or constant which
                         instructs the function to ignore case during the
                         search.

                         .T.            DEFAULT.  Forces the matching process
                                        to adhere to case matching.

                         .F.            Setting this flag to false (.F.)
                                        instructs the function to ignore case
                                        matching.  Therefore, "The" and "the"
                                        will be considered identical for
                                        matching purposes.
      Examples: 

               1.   Search the TARGET text and return the position of every
                    occurrence of the word "the" and ignore case matching.
                    The function will find two occurrences, one at position
                    #13 and the other at position #45.

                    .
                    .
                    .
                    target = 'The quick brown fox jumped over the lazy dog.'
                    offset = 0
                    do while .T.
                         offset = WILDRAT('the', target, offset, .f.)
                         if offset < 1
                              exit
                         endif
                         (do something)
                    enddo
                    .
                    .
                    .

                    The quick brown fox jumped over the lazy dog
                                                   

               2.   Search the TARGET text and return the position of every
                    occurrence of the pattern "t??t" and enforce case
                    matching.  The function will find four occurrences, at
                    positions #10, #13, #20 and #29.

                    .
                    .
                    .
                    pattern = 't??t'
                    target = 'That guy gives tests on text with that book.'
                    offset = 0
                    do while .T.
                         offset = WILDRAT(pattern, target, offset)
                         if offset < 1
                              exit
                         endif
                         (do something)
                    enddo
                    .
                    .

                    That guy gives tests on text with that book.

               3.   Search the TARGET text and return the position of every
                    question mark (?).  As this is the wildcard character
                    remember we must use the literal (\) expression.  The
                    function will find two occurrences, one at position #01
                    and the other at position #12.

                    .
                    .
                    .
                    pattern = '\?'
                    target = 'Did you know?  Does she?'
                    offset = 0
                    do while .T.
                         offset = WILDRAT(pattern, target, offset)
                         if offset < 1
                              exit
                         endif
                         (do something)
                    enddo
                    .
                    .
                    .

                    Did you know?  Does she?
                                          


      Returns: 

               memvar....Number variable which, if greater than zero,
                         indicates the position within the TARGET where the
                         PATTERN was found.  This position is relative to the
                         end of the TARGET not the end of the TARGET+OFFSET.
                         If zero then no match was found.  If less than zero
                         then an error in one of the parameters prevented the
                         search from beginning.


      Cautions: 

               None.

See Also: WILDAT()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson