How can I remove the last character off a string?
COMMUNITY QUESTION
How can I remove the last character off a string?
1 answer
Use the sub method and the # operator.
The sub method takes the following arguments like so, assuming string points to a string
local substring = string:sub(startIndex, endIndex)
where startIndex is the nth character you want the new substring to start at and endIndex is the nth character you want the new substring to end at.
So, for our case, we want startIndex to be 1 and endIndex to be 1 less than the length of the string. We can get the length of the string using the # operator.
local substring = string:sub(1, #string - 1)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I tried stringe= "5555gg" local substring = stringe:sub(1, #string - 1) print(substring), but it only seems to print the first two characters...