CHARAT function
Text
The text string.
Index
The position in the text string where the sought character is.
Returns
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:
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:
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
Returns "e", the second character in the text string "test".
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.
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.
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.