How can I remove the last character off a string?
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)