>- see footer for list info -<
It does, see my previous reply.

--
russ



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Chris Wharton
Sent: 04 October 2007 10:31
To: Coldfusion Development
Subject: RE: [CF-Dev] getting x elements from lists

>- see footer for list info -<
Thanks guys, I went with a UDF, was just surprised that ColdFusion
didn't have a built in function for this.

Chris W.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Adrian Lynch
Sent: 04 October 2007 08:13
To: Coldfusion Development
Subject: RE: [CF-Dev] getting x elements from lists

>- see footer for list info -<
Hey Chris, if you don't like the messy looping, turn it into a UDF...

<cffunction name="SubList">

        <cfargument name="list">
        <cfargument name="from">
        <cfargument name="to">
        <cfargument name="delimiters">

        <cfset var rtnList = "">
        <cfset var i = 0>

        <cfloop from="#ARGUMENTS.from#" to="#ARGUMENTS.to#" index="i">
                <cfset rtnList = ListAppend(rtnList,
ListGetAt(ARGUMENTS.list, i,
ARGUMENTS.delimiters))>
        </cfloop>

        <cfreturn rtnList>

</cffunction>

Then use it like this...

<cfset myList = "2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32">

<cfoutput>

<p>#myList#</p>

<p>#SubList(myList, 5, 7, ",")#</p>

</cfoutput>

I didn't really test it though.

Adrian


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Chris Wharton
Sent: 03 October 2007 14:17
To: [email protected]
Subject: [CF-Dev] getting x elements from lists


>- see footer for list info -<
Hi,



I have a list with a number of elements, for example I might have 10
elements in my list (filled with numbers 1 to 10). What I'd like to do
is get the last 3 elements from my list, maybe I'd like to get the first
3 or the last 5, etc.



Ideally I'd do the following to get the last 3 elements in my list:



myList = "1,2,3,4,5,6,7,8,9,10";

Right(myList, 3);



This doesn't work as ColdFusion treats a List as a String, so the above
will only return the last 3 characters in my list (",10").



I could do the following to get what I need:



<cfset myList = "1,2,3,4,5,6,7,8,9,10">

<cfset myNewList = "">



<cfloop from="0" to="2" index="idx">

            <cfset myNewList = ListAppend(myNewList, ListGetAt(myList,
ListLen(myList) - idx))>

</cfloop>



But I see this looping and having to work out the correct from/to values
a bit messy, there must be an even simpler way, anybody have any tips
for me?



Thanks,

Chris W

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
-<
_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<


_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- cfdeveloper Hosting provided by www.cfmxhosting.co.uk -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to