Jump to content




String Formatting?


  • You cannot reply to this topic
4 replies to this topic

#1 Xenthera

  • Members
  • 170 posts

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. :)

#2 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

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

#3 Xenthera

  • Members
  • 170 posts

Posted 23 December 2012 - 11:43 AM

What does the third number relate to? string.sub([string],[character position],[?])

#4 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

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)
""

#5 Xenthera

  • Members
  • 170 posts

Posted 23 December 2012 - 11:55 AM

Thanks. It worked great!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users