Hi, If I have the following list: <cfset deadWords = "tabs,tablets,caps,capsules,powder"> Code (markup): ...and I have have a simple string. #searchQuery# Code (markup): What is the best and most efficent practise to remove ANY of the strings in the list? So after the process #searchQuery# shouldn't contain any of the words in #deadWords#. Thanks
Came up with a solution for anyone interested <!--- dead words ---> <cfset deadWords = "the,it,and,now,when,how,do"> <!--- limit to 50 chars ---> <cfset searchQuery = left(ARGUMENTS.search,50)> <!--- put words in array ---> <cfset words = listtoarray(searchQuery," ")> <!--- reset ---> <cfset searchQuery = ""> <cfoutput> <!--- ---> <cfloop index="idx" from="1" to="#arrayLen(words)#"> <!--- any dead words? ---> <cfif NOT listFindNoCase(deadWords, words[idx])> <cfset searchQuery = searchQuery & words[idx]> </cfif> </cfloop> PHP:
seems to me you could do the following.. <cfset deadwords = "tabs,tablets,caps,capsules,powder"> <cfset searchQuery= replacelist(searchQuery,deadwords,"")> Code (markup): i'm not entirely sure on how fast the replacelist function works.. but this seems to cut down on code pretty well