Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a search box without it needing the entire name?

Asked by 4 years ago

How do you make a search box that can look through a table without needing the whole name? Eg. if you type "alpha" it would show everything that starts with "alpha" like "Alpha" and "Alphabet" depending on whatevers in the table. Thanks

Note, I'm not looking for someone to write the script - even a wiki link would be handy as all I've found was people talking about web features. Thanks

1 answer

Log in to vote
3
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago

String.match is great in situations like this.

words = {"Test1","Test3","sdfdsf","sdtgr"}

for i,v in pairs(words) do
    local checkMatch = string.match(v,"sd")

    if checkMatch then
        print(v.." matches with sd!")
    else
        print(v.." doesn't match with sd!")
    end
end

In the code above we have a table containing four strings. Once we declare the table we loop through it and check if the item in the table we're checking currently has "sd" in it. If that's the case we print that it does match with sd. If not, we print it doesn't match with it.

Ad

Answer this question