Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to compare two arrays and remove certain words

Status
Not open for further replies.

MrPink1138

Programmer
Jul 10, 2003
34
US
I'm trying to write a search page and having the infamous SQL Server Ignored words problem. Basically what I want to do is to filter out all of the ignored words from what my user entered.
To that end, I have an array which contains all of the SQL ignored words.
I have a 2nd arary which contains my user's search which is basically taking whatever they enter and using a regex string to split it into an array.

What I need to do is loop through the user input array and check to see if any of the words are in the ignored words array. If so, remove them (or we could populate a 3rd "clean" array).

Is there an effecient way of doing this?

I'm thinking I could use some nested loops to check each word in the user array against each word in the ignored words array but I'm wondering if there's a better way.

Any ideas? Thanks in advance
 
I set up the "array" as a static hasttable.

static Hashtable ht = initHash();

static private initHash();
{
wt = new Hashtable(500,
new CaseInsensitiveHashCodeProvider(),
new CaseInsensitiveComparer());
wt.Add("what",What");
.......
return wt;
}

// TEST WOrd
if (ht.ContainsKey(words) ..........

Compare Code
 
Thanks so much for the suggestion. I'm not all that familiar with using HashTables but I will definitelly RTFM. :)
 
I forgot to put in return type.
static private Hashtable initHash();
{
wt = new Hashtable(500,
new CaseInsensitiveHashCodeProvider(),
new CaseInsensitiveComparer());
wt.Add("what",What");
.......
return wt;
}



Compare Code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top