Skip to main content
July 22, 2011
Question

Search the existance of string

  • July 22, 2011
  • 1 reply
  • 341 views

I need to check if the the string contains the word 'board or schools or secondary'.

The below code returns zero as if the word is not present.

<cfset

t1 = "XYZ Schools of Blah">

<cfset

t2 = "XYZ Schools of secondary">

<cfset

t3 = "board Schools of Blah">

<cfset

lst = "board,secondary,schools">

<cfdump

var="#ListContainsNoCase(lst,t1)#">

<cfdump

var="#ListContainsNoCase(lst,t2)#">

<cfdump

var="#ListContainsNoCase(lst,t3)#">

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 22, 2011

    Your logic is backwards.  You are checking to see if the list contains the complete string as opposed to checking to see if the string contains any of the words in the list.  You want something like this:

    found = false:

    ctr = 1;

    while (found is false and ctr lte listlen(lst)) {

    if (YourString contains ListGetAt(lst, ctr))

    found = true;

    else

    ctr = ctr + 1;

    }