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.
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
You can also do
("String"):sub(1,3)Indeed.