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

How to get the first letter?

Is there a way you can get the first letter in a string or the second or whatever number. Through how stuff normally is on roblox studio I originally though it would be like this:

Str = "Stri"
print(Str[3])

but instead it prints nil.

1 comment

0

We are not in python xDDDDD

2 answers

✓ Accepted answer

Strings have something called substring, wich is accesed by doing string:sub(StringValue,start,end)

if we do string.sub("Hello, world!",1,1) we would get H as return.

if we do string.sub("Hello, world!",2,4) we would get ell as return.

you can also do

("Hello"):sub(start,end) or MyStringValue:sub(start,end)

If you have any questions, feel free to post a comment.

Suggest also reading this short wiki article

4 comments

0

thanks you are a legend

0

same

0

super helpful

0

i dont understand how to make it detect like all leters and put it in a value

Str = "Stri"
print(string.sub(Str, 1))

5 comments

0

Post explaination. just posting code doesnt help people learn what it does.

1

this site is toxic as hell im done with it

0

You couldn't honestly believe this was a valid answer is any way shape or form.

2

what the, why did this get 3 downvotes, its literally the same thing as above

0

This does not deserve to get downvoted. Upvote it back!

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