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

Cut Strings

Started by timia2109, 26 December 2013 - 03:49 PM
timia2109 #1
Posted 26 December 2013 - 04:49 PM
Hey everyone,
I had the problem that I want a mini terminal in a programm. So if I start a programm I get tArgs = { . . . } also a table, but how can I get the same in a programm like with read() or how can I make from read() a table like:

local a = "down 5" --instert
local b = {"down", "5"} -- should it be

I hope you can help me!
Thanks,
timia2109
Lyqyd #2
Posted 26 December 2013 - 05:05 PM
You simply split the string and insert each space-delimited chunk of characters in a table:


local stringsTable = {}
local inputString = read()
for match in string.gmatch(inputString, "(%S+)") do
  table.insert(stringsTable, match)
end
timia2109 #3
Posted 27 December 2013 - 02:17 PM
Thank you! It works!