Returns a number that represents the starting position of a string within another string. RAT(†) searches backward from the right end of the target string, and returns a value counting from the beginning of the target.


RAT(<search expC>, <target expC> [, <nth occurrence expN>])

<search expC>

The string you want to search for in <target expC>.

<target expC>

The string in which to search for <search expC>.

<nth occurrence expN>

Which occurrence of the string to find. By default, dBASE Plus searches for the first occurrence from the end. You can search for other occurrences by specifying the number (based on starting from the end), which must be greater than zero.


Use RAT(†) to search for the first or <nth occurrence expN> occurrence of <search expC> in a target string, searching right to left, end to beginning, from the last character to the first character. The search is case-sensitive. Use UPPER(†) or LOWER(†) to make the search case-insensitive.

Even though the search starts from the end of the target string or memo field, RAT(†) returns the numeric position where a search string begins in a target string, counting from the beginning of the target. If <search expC> occurs only once in the target, RAT(†) and AT(†) return the same value. For example, RAT("abc","abcdef") and AT("abc","abcdef") both return 1.

RAT(†) returns 0 when:

The search string isnít found

The search string or target string is empty

The search string is longer than the target string

The nth occurrence you specify with <nth occurrence expN> doesn't exist

To find the starting position of <search expC>, searching from left to right, beginning to end, use AT(†). To learn if one string exists within another, use the substring operator ($).

The lastIndexOf(†) method is similar to the RAT(†) function, but in addition to the syntactic difference of being a method instead of a function and the fact that the position is zero-based, the optional parameter specifies where to start searching instead of the nth occurrence to find.