New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# How to get the first letter?

Asked by 3 years ago
Edited 3 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.

8
RubenKan 3570
3 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 — 3y
0
same User#24403 26 — 1y
0
super helpful greatneil80 2007 — 9mo
-3
Answered by 3 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 3570 — 3y
0
this site is toxic as hell im done with it thehybrid576 288 — 3y
0
You couldn't honestly believe this was a valid answer is any way shape or form. ScriptGuider 5471 — 3y
0
what the, why did this get 3 downvotes, its literally the same thing as above greatneil80 2007 — 9mo