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

How do I get the chars before a specified index?

I want to be able to get all characters before a certain index of a string. eg:

charsBeforeIndex("Stringy", 4) -- Returns "Stri"

I'm stumped on how to come about doing this. Help would be appreciated!!

4 comments

0

string.sub will let you do this when provided a start+end index.

0

print(string.sub("Stringy",1,4))

0

something like that xd

1 answer

✓ Accepted answer

Use string.sub.

print(string.sub("metatables",1,4)) -- prints 'meta'

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