AT Function
Syntax
Arguments
- search_string
A character string.
- string
The character string to examine for occurrences of search_string.
- occurrence
Optional. Default = 1. The integer number specifying which occurrence to return. -1 Specifies the last occurrence of the search_string. If omitted, the first occurrence of the search_string will be returned.
Description
Returns the position where one character string is found in another.
Discussion
AT() returns a position integer indicating where the n th occurrence of the search string begins in the string. If the search_string is not found, AT() returns 0. n is specified through the Number argument. Search is case-sensitive. See ATC() for a case-insensitive version of this function.
Example
at(",", CITYSTZIP, 1) -> 10, if CITYSTZIP contains "Cambridge, MA02139" at("Tim", FIRSTNAME, 1) -> 0, if FIRSTNAME contains "Fred"
Assume that a table contains the city, state, and zip code all in one field (e.g., "Cambridge, MA02139"). Suppose you want to print a report displaying the city, state, and zip code in three separate columns. You can define three calculated fields called CITY, STATE, and ZIP, and use the AT() and SUBSTR()functions to locate, and then the SUBSTR() function to extract, the information from the original CITYSTZIP field. For example, the following expression for the CITY field returns the substring of characters up to one position before the first comma in CITYSTZIP (e.g., "Cambridge").
substr(CITYSTZIP, 1, at(",", CITYSTZIP, 1) - 1)
The expression for STATE returns the two characters starting two positions after the comma (e.g., MA):
substr(CITYSTZIP, at(",", CITYSTZIP,1) + 2, 2)
The expression for ZIP returns the substring containing the last five characters in the field (e.g., "02139"). It does not need to use the AT function:
substr(CITYSTZIP, len( trim(CITYSTZIP) ) - 4, 5)
Number, the optional third argument, enables you to specify which occurrence of the search string you are interested in. For instance:
at("a", "abcd abcd abcd abcd", 3) ? 11
If Number is less than zero (ex., -1), the last occurrence will be returned:
at("a", "abcd abcd abcd abcd", -1) ? 16
Because Number is optional, you can omit it and AT still returns the first occurrence of the Search String:
at("f", "Coffee", 1) -> 3 at("f", "Coffee") -> 3
Limitations
The search string argument is case sensitive.
See Also