Click or drag to resize

At Function

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

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

Parameters

cSearch
Type: String
The substring to search for.
cTarget
Type: String
The string in which to search.  (To start at a specific offset, use At3().)

Return Value

Type: UInt32
The position of the first occurrence of <cSearch> within <cTarget>.  If <cSearch> is not found, At() returns 0.
Remarks
If you only need to know whether a substring exists within another string, use the InStr() function or the $ operator.  To find the last occurrence of a substring within a string, use RAt(). Both the At() and RAt() functions are used with Substr(), Left(), and Right() to extract substrings.
Examples
These examples show typical uses of At():
X#
? At("a", "abcde")                        // 1
? At("bcd", "abcde")                // 2
? At("a", "bcde")                        // 0
This example uses strong typing to split a string based on the position of a comma within the target string:
X#
LOCAL cTarget AS STRING
cTarget := "Langtree, Lilly"
? Substr(cTarget, 1, At(",", cTarget) - 1)        // Langtree
? Substr(cTarget, At(",", cTarget) + 2)                // Lilly
See Also