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

[LUA] how to set a string to a portion of a string?

Started by TheGeek, 06 November 2012 - 03:46 PM
TheGeek #1
Posted 06 November 2012 - 04:46 PM
I am attempting to use the rednet system to network computers together, and I could simplify my code greatly if I could figure out how to set a string to a portion of a string.

For example:

lets say a rednet.broadcast() sent the string "send1 test message"

id,message = rednet.receive()
messagefirst = [the first five characters of message]
messagelast = [the rest of the message]

if message first == "send1" then print(messagelast)


Is this possible in LUA?
Lyqyd #2
Posted 06 November 2012 - 05:26 PM

messagefirst = string.sub(message, 1, 5)
messagelast = string.sub(message, 6)