Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I remove the last character off a string?

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)

1 comment

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.