Click or drag to resize

RAt 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.4a
Syntax
 FUNCTION RAt(
	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#
 1? FilePath("c:\dbf\sales.dbf")        // c:\dbf\
 2FUNCTION FilePath(cFile AS STRING)
 3    LOCAL nPos AS DWORD
 4    LOCAL cFilePath AS STRING
 5    IF (nPos := RAt("\", cFile)) != 0
 6        cFilePath := Substr(cFile, 1, nPos)
 7    ELSE
 8        cFilePath := NULL_STRING
 9    ENDIF
10    RETURN cFilePath
See Also