ListDeleteValue - Remove Part of List
Asked Answered
D

2

8

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>
Diahann answered 27/8, 2012 at 16:3 Comment(2)
There is no such function as ListDeleteValueBabu
Sorry was from some Nadel notes - but it was declared as function - my bad... Only saw the listdeletevalueDiahann
O
12

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>
Oscillogram answered 27/8, 2012 at 16:17 Comment(1)
See caveat in @JamesPrivett's answerSlew
O
3

I Just came across this and I think the solution provided may error if listFind() does not produce a results. You may consider the following

<cfset listPos = ListFind(userssigned,ud,":")>
<cfif listPos>
    <cfset newlist = ListDeleteAt( curlist, listPos , ":") />
</cfif>
Obsessive answered 28/2, 2015 at 17:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.