CHARAT function

CHARAT(text, index) CHARAT(text; index)

text â€” Text or { Text }

The text string.

index â€” Number or { Number }

The position in the text string where the sought character is.

Returns â€” Text or { Text }

The character at the given position.

Returns the character at the given position. CHARAT("test", 2)CHARAT("test"; 2) returns "e", as "e" is the second letter in "test".

This function is specific to Calcapp. Spreadsheet users typically use the MID function to extract single characters from text strings, which Calcapp also supports. CHARAT("test", 2)CHARAT("test"; 2) and MID("test", 2, 1)MID("test"; 2; 1) are equivalent. The third parameter to MID specifies the number of characters to extract.

Returning characters in an array

This function returns multiple characters as an array if one or both parameters are arrays:

CHARAT("test", { 1, 2, 3, 4 })CHARAT("test"; { 1; 2; 3; 4 })

This formula returns the array { "t", "e", "s", "t" }{ "t"; "e"; "s"; "t" }. This can also be written as CHARAT("test", SEQUENCE(LEN("test")))CHARAT("test"; SEQUENCE(LEN("test"))), where LEN returns the length of a text string (4 for "test") and SEQUENCE, when given the sole parameter 4, returns the array { 1, 2, 3, 4 }{ 1; 2; 3; 4 }.

Using TEXTSPLIT to break apart text strings

If the objective is to break apart a text string into an array of its constituent characters, TEXTSPLIT is a better choice:

TEXTSPLIT("test", "")TEXTSPLIT("test"; "")

This formula returns the array { "t", "e", "s", "t" }{ "t"; "e"; "s"; "t" }. The second parameter denotes the separator. If it is set to the empty text string, TEXTSPLIT returns an array where every character occupies its own array element.

Examples

CHARAT("test", 2)CHARAT("test"; 2)

Returns "e", the second character in the text string "test".

CHARAT("a😂b😂c", 4)CHARAT("a😂b😂c"; 4)

Returns "😂", the fourth character in the text string "a😂b😂c". All Calcapp text functions correctly handle the entirety of Unicode, including emojis. This is not true for many popular spreadsheets.

CHARAT("test", { 1, 2, 3, 4 })CHARAT("test"; { 1; 2; 3; 4 })

Returns the array { "t", "e", "s", "t" }{ "t"; "e"; "s"; "t" }. When either parameter is an array, CHARAT is invoked once for every array element and the results are collected in the returned array.

CHARAT("test", SEQUENCE(LEN("test")))CHARAT("test"; SEQUENCE(LEN("test")))

Returns the array { "t", "e", "s", "t" }{ "t"; "e"; "s"; "t" }. LEN returns the length of a text string (4 for "test") and SEQUENCE, when given the sole parameter 4, returns the array { 1, 2, 3, 4 }{ 1; 2; 3; 4 }. When either parameter is an array, CHARAT is invoked once for every array element and the results are collected in the returned array.

TEXTSPLIT("test", "")TEXTSPLIT("test"; "")

Returns the array { "t", "e", "s", "t" }{ "t"; "e"; "s"; "t" }. The second parameter is the delimiter. If it is set to "", as is done here, TEXTSPLIT returns an array where every character occupies its own array element.