$^//.{#}/S1//.$/
Try it online!
The input format is as such:
string
index
And the program is 1-indexed.
Explanation
Carrot has several global variables, one for each type: string, float and array (others to be implemented soon). The program starts in string-mode, where all the operators will affect the global string variable. And I call these variables the "stack".
(Example input: abcdef\n3
)
$ Get the first line of the input and set the stack-string to this value
^ Exit caret-mode
stack-string = "abcdef"
/ Operator (behaves differently depending on the argument)
/.{#}/ And the argument to this operator is a regex, so this program gets the matches of this regex into the stack-array
. Any character
{#} Pops a line from the input. So now this evaluates to # of any character where # is the second line of the input (in this case, 3)
stack-array = ["abc"]
And now we just need to get the last character in this string, but first
S1 Join the array on the number 1 and set this to the stack-string. Because the array only contains one element, the number 1 does not appear in the stack-string.
stack-string = "abc"
/ Operator; because the argument is a regex, this retrieves the matches of the regex:
/.$/ Get the last character in the string
stack-array = ["c"]
Now this returns a one element array containing a string of length one, but it is shown as a string in the website.
If we really wanted to give the result as a string, we could easily do S","
at the end, but it doesn't matter because the output still looks the same on the interpreter.