Click or drag to resize

At Function

X#
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.21
Syntax
 FUNCTION At(
	cSearch AS STRING,
	cTarget AS STRING
) AS DWORD
Request Example 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: DWord
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#
1? At("a", "abcde")            // 1
2? At("bcd", "abcde")        // 2
3? 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#
1LOCAL cTarget AS STRING
2cTarget := "Langtree, Lilly"
3? Substr(cTarget, 1, At(",", cTarget) - 1)    // Langtree
4? Substr(cTarget, At(",", cTarget) + 2)        // Lilly
See Also