Text.At
TextReturns the character at the specified zero-based index position in a text value.
Syntax
Text.At(text as nullable text, index as number) as nullable textParameters
| Name | Type | Required | Description |
|---|---|---|---|
text | text | Yes | The source text value. |
index | number | Yes | The zero-based index of the character to return. |
Return Value
text — A single-character text value at the given index.
Remarks
Text.At returns a single character from text at the specified zero-based index. The first character is at index 0. It is equivalent to Text.Middle(text, index, 1) but expresses single-character access more clearly.
If text is null, the function returns null. If index is out of range — negative, or equal to or greater than the text length — an error is raised. Always validate the index or text length before calling this function on variable-length data to avoid runtime errors.
Use Text.At when you need a specific character by position. For extracting a range of characters, use Text.Middle or Text.Range. For iterating over every character, Text.ToList is more efficient than calling Text.At in a loop. To find the position of a character rather than retrieve it, use Text.PositionOf.
Examples
Example 3: Read the separator character in a formatted string
let
code = "US-12345",
sep = Text.At(code, 2),
isValid = sep = "-"
in
isValidThe final output — checks whether the extracted separator character equals "-", returning true if the format is valid.
Result | |
|---|---|
| 1 | TRUE |