>- see footer for list info -<
Here you go:
<cffunction name="ListRight" returntype="String" output="false">
    <cfargument name="List"      type="String"/>
    <cfargument name="Limit"     type="Numeric"/>
    <cfargument name="Delimiter" type="String" default=","/>
    <cfset var Result = -1/>
    <cfif ListLen(Arguments.List,Arguments.Delimiter) LTE Arguments.Limit>
        <cfset Result = Arguments.List/>
    <cfelse>
        <cfset Result = REReplace(Arguments.List
,'^.*((#Arguments.Delimiter#[^#Arguments.Delimiter#]*){#Arguments.Limit#})$','\1')/>
        <cfset Result = REReplace(Result,'^#Arguments.Delimiter#','')/>
<!--- Removes preceeding delimiter --->
    </cfif>
    <cfreturn Result/>
</cffunction>


<cfdump var="#ListRight('1,2,3,4,5,6,7,8,9,10',3)#"/>



On 10/3/07, Chris Wharton <[EMAIL PROTECTED]> wrote:
>
> >- 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
> -<
>



-- 
\ \
Peter Boughton
blog.bpsite.net
/ /
_______________________________________________

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