Extracting last n characters with lua

I would like to extract the last N characters from a lua string.

How could I use this?

+3


source to share


2 answers


Use string.sub

with a negative index.

Example



string.sub("Hello world", -5) -- => world

      

+3


source


local n = 3
local mystring = "I am to lazy to google a solution or read the Lua manual"

local nLastCharacters = string.sub(mystring, -n)

      



+2


source







All Articles