Search code examples
stringluatrim

How do I delete the first character on a string? [Lua]


Basically, I have a string in Lua, which is a user output, but I want to trim the first character cause I don't really need it. How can I do that?


Solution

  • You cannot delete the first character of a string.

    But you can copy a substring that starts from the second character using string.sub

    string.sub(s, i [,j])

    Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length)....

    So str = str:sub(2) will give you the substring of str that starts at character 2 which is what you want.