Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Getting first characters of a string?

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

✓ Accepted answer

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 comments

2

You can also do ("String"):sub(1,3)

0

Indeed.

This discussion is preserved as it was. New answers, comments, and votes are closed.