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

How do I get the first character in a string?

Asked by
Mystdar 352 Moderation Voter
8 years ago

I want to get just he first character in a string

string = "Hello"

print(string[1])
print(string:sub(1))
print(string.sub(1))

None of these worked.

0
DevArk is correct but a quicker way to call it is: print(string:sub(1,1)) IXLKIDDO 110 — 8y

1 answer

Log in to vote
1
Answered by
DevArk 50
8 years ago

Well "string" is a keyword used by lua i recommend not making a variable called that try something like str?

print(string.sub(str, 1,1))

0
Good answer, but next time try to put your code in a code block. :) ChemicalHex 979 — 8y
Ad

Answer this question