DreTaX
DreTaX

Reputation: 836

Extracting the last N characters of string in Lua?

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

Answers (2)

Termininja
Termininja

Reputation: 7036

You can also use this variant:

('Hello world'):sub(-5)  --> world

Upvotes: 8

mleko
mleko

Reputation: 12233

Use string.sub with negative index.

Example

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

Upvotes: 34

Related Questions