>- see footer for list info -<
http://www.cfquickdocs.com/?getDoc=ListGetAt

--
Russ Michaels

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On 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 -<

Reply via email to