How do i get a certain character from a string?

how would i get a certain character from a string?
for example, how would i get the third character from “abc”, which would be “c” in this case?

4 Likes

If you want to get the third character from a string, you can just do

string.sub(yourString,3,3)

Where yourString is the string you want to take a certain character from and 3 being which position to take

Depending on the usecase, you may have to use something else. Like to find a certain character, you’d use string.match

string.match(yourString,"c")

If you wanted to check if a string had the letter c or not

12 Likes

Hey, I can help :grinning_face_with_smiling_eyes:

string.sub("abc",3,3)

This would be the same for other strings obviously changing it to get the character you want.

4 Likes

Oops, Sorry I didn’t see you’d posted something similar :sweat_smile:

3 Likes

Completely fine! You still wanted to help and I respect that!

2 Likes

thanks, that works just about right

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

Sorry, but what does the second 3 do?

1 Like

string.sub(str, s, e) is designed to return a string starting at s and ending at e. If you want to just get one character, you can use the same number for both s and e.

3 Likes