开发者

ColdFusion-9 "includeEmptyValues"

开发者 https://www.devze.com 2023-03-22 21:43 出处:网络
This is my code: returnStruct.myList = myList; returnStruct.first = trim(ListGetAt(myList,3)); returnStruct.last = trim(ListGetAt(myList,13));

This is my code:

returnStruct.myList = myList;
returnStruct.first = trim(ListGetAt(myList,3));
returnStruct.last = trim(ListGetAt(myList,13));
returnStruct.address = trim(ListGetAt(myList,15));
returnStruct.city = trim(ListGetAt(myList,2));
returnStruct.state = trim(ListGetAt(myList,9));

Everything is working fine until myList hits empty values and then everything crashes. I found a command "includeE开发者_运维问答mptyValues" that I can set to 'yes' but I am not familiar with it and the documentation of ColdFusion 9 isn't the best I've come across.


http://cfquickdocs.com/cf9/#listgetat

Previous versions of ColdFusion (and CF9 by default) counted consecutive delimiters as a single delimiter. So a list that looked like this:

<cfset myList="a,b,,c,,d" />

was considered to have four elements.

Recently added is the "includeEmptyValues" attribute.

listGetAt(list, position [, delimiters, includeEmptyValues ])

So while

<cfset myVar=listGetAt(myList,6) />

will throw an error

<cfset myVar=listGetAt(myList,6,",","true") />

will successfully set myVar to d.


might want to use listToArray(), and ArrayIsDefined(). Play with includeEmptyFields attr and see which behavior you prefer. True = Convert empty elements in a list to empty array entries

0

精彩评论

暂无评论...
验证码 换一张
取 消