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

String Manipulation Help

Started by DarkNinja2462, 08 April 2012 - 12:49 AM
DarkNinja2462 #1
Posted 08 April 2012 - 02:49 AM
Is it possible to take a piece of a string, and get the length of a string?
I know they have that for the TI-84 plus.
Can you give me the syntax, or at least where to find it?
RECAP: Can I take a piece of a string and find the length of it?
MysticT #2
Posted 08 April 2012 - 02:53 AM
You can use string.sub to get substrings, and string.len or the lenght operator (#).

local s = string.sub(your_string, pos1, pos2)
print("The substring is: ", s)
print("It's lenght is: ", #s)
Check out this link for more lua string functions: StringLibraryTutorial
EatenAlive3 #3
Posted 08 April 2012 - 03:02 AM
Length usage:

string = "cabbage"
return string:len()
> returns 7
Hawk777 #4
Posted 08 April 2012 - 08:34 AM
If you take substrings, be aware of this bug.