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

String Formatting?

Started by Xenthera, 23 December 2012 - 10:28 AM
Xenthera #1
Posted 23 December 2012 - 11:28 AM
Hi there, I'm working on a seven segment display that's all digital. Right now i'm trying to set a system where you can display the number you typed over 3 displays. I'm also using rednet to accomplish this. My problem is I can only send each display a variable of 0-9. So sending "593" would not work. So if I can take that and split it up into "5" "9" and "3" that would be great. I just don't know how to do that. Any help would be useful. :)/>
PixelToast #2
Posted 23 December 2012 - 11:34 AM
you want string.sub

if str is "5689" then
tonumber(string.sub(str,1,1))
will return 5
and
tonumber(string.sub(str,2,2))
will return 6

etc
Xenthera #3
Posted 23 December 2012 - 11:43 AM
What does the third number relate to? string.sub([string],[character position],[?])
PixelToast #4
Posted 23 December 2012 - 11:48 AM
end character position
i would suggest you
RTFM

> string.sub("herrow",2,4)
"err"
> string.sub("herrow",1,-2)
"herro"
> string.sub("herrow",2,1)
""
Xenthera #5
Posted 23 December 2012 - 11:55 AM
Thanks. It worked great!