View previous topic :: View next topic |
Author |
Message |
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Fri Feb 17, 2017 12:41 pm Post subject: Lua search/find function |
|
|
How can I implement a search function for a large list, i.e. with an editbox to input the keyword to search for and a list that populated only the matched items by caption?
edit: To clarify better I'm basically trying to do something like this
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Fri Feb 17, 2017 6:01 pm Post subject: |
|
|
Code: | local list_of_items = {
"Red Apple",
"Orange Carrot",
"Red Pepper"
}
local string_to_find = "Red"
local new_list = {}
for i, v in ipairs(list_of_items) do
if v:find(string_to_find) then
table.insert(new_list, v)
end
end
print("Found:")
for i, v in ipairs(new_list) do
print(" "..v)
end |
|
|
Back to top |
|
|
usernotfound Expert Cheater Reputation: 0
Joined: 21 Feb 2016 Posts: 115
|
Posted: Fri Feb 17, 2017 6:14 pm Post subject: |
|
|
Awesome thank you yet again Zanzer, much easier to sort through lists this way
|
|
Back to top |
|
|
|