Click or drag to resize

RAt2 Function

Return the position of the last occurrence of a substring within a string.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax
 FUNCTION RAt2(
	cSearch AS STRING,
	cTarget AS STRING
) AS DWORD
View Source

Parameters

cSearch
Type: String
The substring for which to search.
cTarget
Type: String
The string in which to search.  (To specify an offset, use RAt3()).

Return Value

Type: UInt32
The position of <cSearch> within <cTarget>.  If <cSearch> is not found, RAt() returns 0.
Remarks
RAt() is like At(), which returns the position of the first occurrence of a substring within another string.  If you only need to know whether a substring exists within another string, use the InStr() function or the $ operator.   Both the RAt() and At() functions are used with Substr(), Left(), and Right() to extract substrings.
Examples
This example uses RAt() to create a function, FilePath(), that extracts the path from a file specification.  If the path is unspecified, FilePath() returns a NULL_STRING:
X#
? FilePath("c:\dbf\sales.dbf")                // c:\dbf\
FUNCTION FilePath(cFile AS STRING)
        LOCAL nPos AS DWORD
        LOCAL cFilePath AS STRING
        IF (nPos := RAt("\", cFile)) != 0
                cFilePath := Substr(cFile, 1, nPos)
        ELSE
                cFilePath := NULL_STRING
        ENDIF
        RETURN cFilePath
See Also