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

How to find the number of characters in longest string in a table?

Started by CreeperWithShades, 22 February 2014 - 01:15 PM
CreeperWithShades #1
Posted 22 February 2014 - 02:15 PM
Hello, i need a function to find the number of characters in longest string in a table. Say I have:
table = {"Files, "Derpstuff", "Bin"}
I want the function to return 9.

Help appreciated!
Thib0704 #2
Posted 22 February 2014 - 07:11 PM

function getLength(tbl)
local MaxSize = 1
    for _, val in pairs(tbl) do
        if #val > MaxSize then
       	  MaxSize = #val
        end
    end
        return MaxSize
end

Not tested.
EDIT: Wait a sec, Its not working.. :P/>
EDIT2: This works.
Edited on 22 February 2014 - 06:33 PM