A part of a string variable shall be assigned to another variable, how does it work?

Q

A part of a string variable shall be assigned to another variable, how does it work?

A

Use the string.sub() operator. You need to specify the first and the last character that shall be cut out. It starts counting with 1. Negative values counting characters in the string from behind, starting with -1 as last character.

Example code:

string_a = “Hello“
extract_a = string.sub(string_a,2,4)
-- will result in value “ell“ for variable extract
extract_b = string.sub(string_a,2,-2)
-- same result