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

How do I remove letters from a string at the start? [SOLVED]

Asked by 8 years ago

I currently have this piece of code:

text = "asdfghjkl"
text = text:sub(1, #text - 3)
texta.Text = (text)

On the 2nd line, it removes three letters from the END of the string so the string would now become "asdfgh". My question is, how do I remove it at the start? I've tried everything I could think of currently.

Thank you!

2
Have you tried text:sub(4)? Gets the fourth character and forward to return "fghjkl". M39a9am3R 3210 — 8y
0
.-. was it seriously that easy. Thank you. WelpNathan 307 — 8y

1 answer

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Try: text:sub(4)

It will get the fourth character and forward in your script to return "fghjkl".

The reason behind this is the first argument of string.sub() (of course is the string, but I mean in function form) is the beginning of where you want to start in the string. That first number will determine where the string will start, if the second argument is left blank then it will return the remainder of the string as well. This can be useful in admin commands if you were to want to find out if someone said "kill/" after the prefix "hello ".

Player.Chatted:connect(function(String)
    if String:sub(7) == 'kill/' then
        --Of course you would need more code to find out if they actually said a prefix hello.
    end
end
Ad

Answer this question