So I have a program that needs to take a string received through rednet, and determine what the last few letters are.
I have set up a string.sub to handle this that looks like this:
id, message = rednet.receive()
messagesub = string.sub(message, pos1, pos2)
I've tried:
local messagelength = #message - 4 --subtract for from the total length
message = string.sub(message, messagelength)
However, its keeps giving me an error, "attempt to get length of nil"
what I was wondering is if there is a way to get the last 4 letters of the string. Any help is appreciated!
string.sub question
Started by Varscott11, Jun 26 2016 03:58 PM
3 replies to this topic
#1
Posted 26 June 2016 - 03:58 PM
#2
Posted 26 June 2016 - 04:06 PM
string.sub(message, -4) --#Last 4 characters in the string
Edited by TYKUHN2, 26 June 2016 - 04:06 PM.
#3
Posted 26 June 2016 - 04:09 PM
Thanks for the reply! trying it now
Why thank you good sir. It works!
Why thank you good sir. It works!
#4
Posted 26 June 2016 - 04:39 PM
Or even...
Your "attempt to get length of nil" error would suggest that 'message' was nil, however, so when you tried "#message", it errored.
message:sub( -4 )
Your "attempt to get length of nil" error would suggest that 'message' was nil, however, so when you tried "#message", it errored.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











