Search Array of String for exact match words
I need to create a search feature.
There will be a textfield where the user will input a word or words.
Then I need to check if the are any reference in the array of names.
namesArray ["ocean in the sky", "cean on sky", "cean is white"];
keywordsArray ["cean", "sky"];
matchCounter = 0;
If I input the word "cean" I dont want in my results "ocean in the sky", only "cean is sky".
I have the following code:
for (var j:int = 0; j < namesArray.length; ++j)
{
var tempStr:String = namesArray
; for (var k:int = 0; k < keywordsArray.length; ++k)
{
if (tempStr.indexOf(arrayKeywords
) != -1) {
matchCounter++;
}
}
if(lengthKeywords == matchCounter)
{
trace("yeahhh... there's a match!!");
}
matchCounter = 0;
}
Is there a better way? How can I do this?