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.21
Syntax FUNCTION At(
cSearch AS STRING,
cTarget AS STRING
) AS DWORD
public static uint At(
string cSearch,
string cTarget
)
Request Example
View SourceParameters
- 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():
1? At("a", "abcde")
2? At("bcd", "abcde")
3? At("a", "bcde")
This example uses strong typing to split a string based on the position of a comma within the target string:
1LOCAL cTarget AS STRING
2cTarget := "Langtree, Lilly"
3? Substr(cTarget, 1, At(",", cTarget) - 1)
4? Substr(cTarget, At(",", cTarget) + 2)
See Also