Reputation:
So I have a dictionary:
local toFind = "Layla"
local songs = {
{name = "Eric Clapton - Layla", id = "123"},
{name = "Eric Clapton - I Shot The Sheriff", id = "321"}
}
Is it possible to use string.find(songs, toFind)
or something similar to find the table that contains the "Layla" string?
Upvotes: 0
Views: 474
Reputation: 2823
All strings have string functions attached as methods.
Therefore you can directly do...
for k,v in pairs(songs) do
if v.name:find(toFind) then
return songs[k], v.name
end
end
...that returns the table and the full Text...
table: 0x565cbec0 Eric Clapton - Layla
Upvotes: 1