C5_RAT

 RAT()
 Return the position of the last occurrence of a substring
------------------------------------------------------------------------------
 Syntax

     RAT(<cSearch>, <cTarget>) --> nPosition

 Arguments

     <cSearch> is the character string to be located.

     <cTarget> is the character string to be searched.

 Returns

     RAT() returns the position of <cSearch> within <cTarget> as an integer
     numeric value.  If <cSearch> is not found, RAT() returns zero.

 Description

     RAT() is a character function that returns the position of the last
     occurrence of a character substring within another character string.  It
     does this by searching the target string from the right.  RAT() is like
     the AT() function, which returns the position of the first occurrence of
     a substring within another string.  RAT() is also like the $ operator,
     which determines whether a substring is contained within a string.

     Both the RAT() and AT() functions are used with SUBSTR(), LEFT(), and
     RIGHT() to extract substrings.

 Examples

     .  This example uses RAT() to create a user-defined function,
        FilePath(), that extracts the path from a file specification.  If the
        path is unspecified, FilePath() returns a null string (""):

        ? FilePath("C:\DBF\Sales.dbf")      // Result: C:\DBF\

        FUNCTION FilePath( cFile )
           LOCAL nPos, cFilePath
           IF (nPos := RAT("\", cFile)) != 0
              cFilePath = SUBSTR(cFile, 1, nPos)
           ELSE
              cFilePath = ""
           ENDIF
           RETURN cFilePath

 Files   Library is EXTEND.LIB.

See Also: RIGHT() STRTRAN() SUBSTR()

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.