Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting first characters of a string?

Asked by
iFlusters 355 Moderation Voter
7 years ago
Edited 7 years ago

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.

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

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
2
You can also do `("String"):sub(1,3)` Vrakos 109 — 7y
0
Indeed. OldPalHappy 1477 — 7y
Ad

Answer this question