Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting the last N characters of string in Lua?

Tags:

string

lua

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

What way I could use to achieve this?

like image 831
DreTaX Avatar asked Jul 22 '17 14:07

DreTaX


People also ask

Which function is used to extract the last 3 characters of the string *?

Get the last character of string using len() function.

How do I pull the last 4 characters in R?

To get the last n characters from a string, we can use the stri_sub() function from a stringi package in R. The stri_sub() function takes 3 arguments, the first one is a string, second is start position, third is end position.


1 Answers

Use string.sub with negative index.

Example

string.sub("Hello world", -5) -- => world
like image 105
mleko Avatar answered Oct 21 '22 23:10

mleko