Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to get the first letter?

Asked by 2 years ago
Edited 2 years ago

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.

2 answers

Log in to vote
5
Answered by
RubenKan 3473 Moderation Voter Administrator Community Moderator
2 years ago

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

0
thanks you are a legend shabbs15 67 — 2y
0
same incapaxx 3361 — 3mo
Ad
Log in to vote
-3
Answered by 2 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
Str = "Stri"
print(string.sub(Str, 1))
0
Post explaination. just posting code doesnt help people learn what it does. RubenKan 3473 — 2y
0
this site is toxic as hell im done with it thehybrid576 283 — 2y
0
You couldn't honestly believe this was a valid answer is any way shape or form. ScriptGuider 5261 — 2y

Answer this question