Jump to content

[HELP] String From Table


Recommended Posts

Hi good evening everyone, I have below a table of strings 
How can I loop through this table and return only the longest string? which in this case is: "The Longest String Of Text" ?

exampleTable = { "stringitem1", "stringitem22", "stringitem333", "The Longest String Of Text", "abcde" }

 

Link to comment
local exampleTable = {"stringitem1", "stringitem22", "stringitem333", "The Longest String Of Text", "abcde"}

function getLongestString(strTable)
   local str = strTable[1]
   for i=1,#strTable do
   	  if string.len(strTable[i]) > string.len(str) then
         str = strTable[i]
   	  end 
   end
   return str
end

print(getLongestString(exampleTable)) --result : The Longest String Of Text

try this

  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...