How can I get the first characters, say my string is
'hellothere'
how do I get the first four characters ( hell ). I've tried:
string.gsub(s, "^%d%d%d%d")
but it does not work.
gsub
is for finding and replacing a pattern in a string. eLunate explains gsub very well here. Just use string.sub()
.
You can read more about string manipulation here.
An example script would follow as so:
local String = "Hello, World!" local newString = string.sub(String,1,5) print(newString) --// OUTPUT Hello