Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ListLen() return Values

Explorer ,
Feb 23, 2011 Feb 23, 2011

I'm using ListLen function to detect whether a column has a  value or not. If the column has a value, the value is going to be a comma delimited value such as a,b,c,d,e,f etc

otherwise it could be just blank (Null or a space) NOT an empty comma delimited.

So when I do the following:

<CFIF LisLen(GetQuery.ColumName) IS .....>  here where I'm not sure what to do. Should I say: <CFIF LisLen(GetQuery.ColumName) IS 0 > Or should I say:

<CFIF LisLen(GetQuery.ColumName) IS " " >

I googled and read CF textbook, all mentioned only when ListLen is evaluating a list not an empty value. Please help! Thanks a bunch!

TOPICS
Getting started
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 23, 2011 Feb 23, 2011

Well, according to the docs what datatype does listLen return? Integer. Therefore it'll never return " ".

However, why not just *try* it? What happens if you just output listlen(" ") to the screen? You'll soon find out.

Although in this case listLen would probably work fine, be careful about using functions for purposes for which they weren't explicitly designed. In this example yes, this will work, but what if Adobe one day decide that a "list" must be a string of 1 or more characters? This method would no longer work.

Perhaps to be on the safe side:

<cfif myVal NEQ "" > <!--- or len(myVal) GT 0 --->

  I have a value!

  <cfif listLen(myVal GT 0 >

    It's a list!

  </cfif>

  But it's not a list.

</cfif>

Just something to consider. But as for the original question, just try it! There's currently no such thing as a null in ColdFusion, it'll default a null string column to an empty string. Give it a go with the various values you might be reading and test for yourself that it'll work.

O.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 23, 2011 Feb 23, 2011

Just to add to the previous response, to avoid space use trim().

<cfif ListLen(Trim(GetQuery.ColumName))>

  Actions for the list

<cfelse>

      Actions if not a list

</cfif>

I hope boolean operation is faster than string comparsion.. (EQ " ")

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2011 Feb 25, 2011

As you are getting data from query you can you use coldfusion listfunction named "valuelist(query.column [, delimiter ])" which convert a query column to list and ListLen(list [, delimiters ]) which return the length of a list.

So you can write code  as follow  to achive desired result.

<cfquery name = "GetCourseList" datasource = "cfdocexamples">

    SELECT *

    FROM CourseList

    WHERE Dept_ID = 'BIOL'

</cfquery>

<cfif listlen(valuelist(GetCourseList.Course_ID,","),",")>

<cfoutput>List exist</cfoutput>

<cfelse>

<cfoutput>List blank</cfoutput>

</cfif>

Hope above will work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 25, 2011 Feb 25, 2011
LATEST

Well, here's the docs:

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6d6c.html

And they say the function returns "Integer; the number of elements in a list"

So ask yourself this... how many list elements does an empty string have?

Or, indeed, as Owain suggests: just try it.  Isn't that easier than taking all the time to write a post here?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources