Function RAt() Foundation

Determines the position of last occurrence of a substring within a character string.

Syntax
RAt( <cSeek>, <cString>, [<nStartPos>] ) --> nPosition
Parameters
<cSeek>
<cSeek> is a character or a string whose position in <cString>is determined.
<cString>
<cString> is the character string searched.
<nStartPos>
The optional numeric parameter <nStartPos> defines the position within <cString> to start the search from. It defaults to Len(<cString>).
Return

RAt() searches the character string <cString> from the end (from the right) and returns the last position of <cSeek> as an integer numeric value. When <cSeek> is not found in <cString>, the return value is zero.

Description

The character function RAt() determines the last position of a character substring within another character string. <cString> is searched from the right. The counterpart of RAt() is the function At() which searches a character string from the left (beginning) and determines the position of the first occurrence of a character substring within another character string. The $ operator is also similar and tests whether or not a character string is contained within another.

The functions RAt() and At() are often used in connection with the functions SubStr(), Left() or Right() to perform character string operations.

Examples
RAt()

// The example determines the path name from a 
// complete file name. 

PROCEDURE Main 
   LOCAL cFileName := "C:\XBASE\APPS\DBF\CUSTOMER.DBF" 

   ? PathName( cFileName ) 

RETURN 

FUNCTION PathName( cFileName ) 
   LOCAL cPathName := "" 
   LOCAL nPosition := RAt( "\", cFileName ) 

   IF nPosition > 0 
      cPathName := Left( cFileName, nPosition ) 
   ENDIF 

RETURN cPathName 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.