How to get the exact letter in a string and if not then ignore

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mrpaolosarino

I know that

var Q = "qwerty"
print(Q[5])

it will print y

but what if the string is always changing:

var Q = "qwerty"
func   ready():
           Q = "ok"
           print(Q[5])

This will return an error of Invalid get index ‘5’ (on base: ‘String’).
I want to make it ignore if it doesn’t have that index and just return null. Anyone??

:bust_in_silhouette: Reply From: exuin

Since there is no catching exceptions with GDscript, just use an if statement to check if the length of the string is greater than the index.