Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListDeleteValue - Remove Part of List

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>
like image 656
Merle_the_Pearl Avatar asked Aug 27 '12 16:08

Merle_the_Pearl


People also ask

How do you remove part of a list in Python?

The remove() method is one of the ways you can remove elements from a list in Python. The remove() method removes an item from a list by its value and not by its index number.

How do I remove a specific index from a list in Python?

You can use the pop() method to remove specific elements of a list. pop() method takes the index value as a parameter and removes the element at the specified index. Therefore, a[2] contains 3 and pop() removes and returns the same as output.


1 Answers

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>
like image 96
Matt Busche Avatar answered Sep 22 '22 18:09

Matt Busche