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

How to get the first letter?

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

0
We are not in python xDDDDD PolizeiRoblox123 0 — 3y

2 answers

Log in to vote
8
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 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 — 7y
0
same User#24403 69 — 5y
0
super helpful greatneil80 2647 — 5y
0
i dont understand how to make it detect like all leters and put it in a value MadnessMyth 10 — 4y
Ad
Log in to vote
-2
Answered by 7 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 3615 — 7y
1
this site is toxic as hell im done with it thehybrid576 294 — 7y
0
You couldn't honestly believe this was a valid answer is any way shape or form. ScriptGuider 5640 — 7y
2
what the, why did this get 3 downvotes, its literally the same thing as above greatneil80 2647 — 5y
0
This does not deserve to get downvoted. Upvote it back! Xapelize 2658 — 3y

Answer this question