Skip to main content
October 21, 2010
Answered

Dealing with a parenthesis

  • October 21, 2010
  • 2 replies
  • 1319 views

Morning.

I want to write an if statement that uses CONTAINS to find if a paranthesis exists in my db field.

I have some values stored that may contain parantheses and I want to find them like this.

Field values:

Bill (short)

Larry (tall)

Sam

Frank

Susan

Mary (mean)

Let's say I query the table so it pulls the names I listed above.  Then with my if I want to show only those with the paranthesis.

I am trying to do it like so:

<cfif #name# CONTAINS "(">

show

</cfif>

But it is ignoring that.

Can someone please help?

    This topic has been closed for replies.
    Correct answer Owainnorth

    Idesdema wrote:

    <cfoutput query="people_with_parens">

    <cfif #first_name# CONTAINS "(">

    I don't see how this would matter, ColdFusion is usually pretty forgiving of this error.  But your syntax has unnecessary pound|hash marks.  You don't need them in the <cfif....> statement.  It would normally be written as.

    <cfif first_name CONTAINS "(">

    Or maybe better yet:

    <cfif people_with_parans.first_name CONTAINS "(">

    Still not the whole story I suspect, try pasting up your *actual* code. I just did this, which works perfectly:

    <cfscript>
        people_with_parens = queryNew("first_name", "VarChar") ;
        queryAddRow(people_with_parens) ;
        querySetCell(people_with_parens, "first_name", "Dave" ) ;
        queryAddRow(people_with_parens) ;
        querySetCell(people_with_parens, "first_name", "Bill (short)" ) ;
        queryAddRow(people_with_parens) ;
        querySetCell(people_with_parens, "first_name", "Larry (tall)" ) ;
        queryAddRow(people_with_parens) ;
        querySetCell(people_with_parens, "first_name", "Steve" ) ;
        queryAddRow(people_with_parens) ;
        querySetCell(people_with_parens, "first_name", "Mary (mean)" ) ;
    </cfscript>

    <cfoutput query="people_with_parens">
        <cfif #first_name# CONTAINS "(">
            #first_name#
        </cfif>
    </cfoutput>

    Outputs:

    Bill (short) Larry (tall) Mary (mean)

    2 replies

    Owainnorth
    Inspiring
    October 21, 2010

    Hmm, sounds a lot like half a story to me

    Inspiring
    October 21, 2010

    This - http://forums.adobe.com/thread/607238 - is a "must read" for everyone posting question here, I reckon.

    --

    Adam

    October 21, 2010

    My bad.  I figured just the if statement would suffice.

    Ok this isn't the "real" code but its close enough to understand.

    <cfquery name="people_with_parens" datasource="db">
    SELECT first_name
    FROM people
    </cfquery>

    <cfoutput query="people_with_parens">
    <cfif #first_name# CONTAINS "(">
    #first_name#
    </cfif>
    </cfoutput>

    =====================================

    Result

    Nothing

    Expected Result

    Bill (short)

    Larry (tall)

    Mary (mean)

    Inspiring
    October 21, 2010

    Can you pls show a complete & self-contained example of this "not working"?

    --

    Adam