This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ebernerd's profile picture

Help with strings.

Started by ebernerd, 01 February 2015 - 02:09 AM
ebernerd #1
Posted 01 February 2015 - 03:09 AM
I'm stuck with something
So, I am writing something that requires a certain character of a string. So, like, is there a way to return… say, the third letter of the string "love"? And it would return "v"?

Any idea?
KingofGamesYami #2
Posted 01 February 2015 - 03:09 AM

print( string.sub( "love", 3, 3 ) )
Quintuple Agent #3
Posted 01 February 2015 - 03:33 AM
Just to elaborate further, string.sub() takes (string,starting point,[ending point]), if no ending point is given it will just go to the end of the string.
You can also use negatives to work at the end of the string, such as

string.sub("love",-2)
would return "ve"
http://lua-users.org...LibraryTutorial
Edited on 01 February 2015 - 02:34 AM