Reputation: 836
I would like to extract the last N characters from a Lua string.
What way I could use to achieve this?
Upvotes: 20
Views: 22939
Reputation: 7036
You can also use this variant:
('Hello world'):sub(-5) --> world
Upvotes: 8
Reputation: 12233
Use string.sub
with negative index.
Example
string.sub("Hello world", -5) -- => world
Upvotes: 34