MrCode Posted May 31 Share Posted May 31 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
βurak Posted May 31 Share Posted May 31 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 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now