ListDeleteValue - Remove Part of List

Merle_the_Pearl picture Merle_the_Pearl · Aug 27, 2012 · Viewed 11k times · Source

Trying to remove a userid from a given list. Can't seem to crack it... Errors on the removal at the ListDeleteValue - something I'm missing. On CF8.

 <cfset curlist = "#userssigned#"> - say userx:usery:userz
 <cfset ud = "#session.user_id#"> - say userz

 <cfoutput>
 #curlist#
 <br>
 <br>
 #ud#
 <br>

 <cfset newlist = ListDeleteValue( curlist, "#ud#", ":") />

 #newlist# - should delete userz? end up as userx:usery
 </cfoutput>

Answer

Matt Busche picture Matt Busche · Aug 27, 2012

You need to use ListDeleteAt() and also need to find the position of the item in the list using ListFind() This code works below

Note: You don't need to use "##" when you're setting a variable to another variable

<cfset userssigned = 'userx:usery:userz' />
<cfset session.user_id = 'userz' />

<cfset curlist = userssigned />
<cfset ud = session.user_id />

<cfoutput>
 #curlist#<br><br>
 #ud#<br>
 <cfset newlist = ListDeleteAt( curlist, ListFind(userssigned,ud,":"), ":") />
 #newlist# - should delete userz? end up as userx:usery
</cfoutput>