Using the delete () of () list block, one can remove a specified item from a list based on its numerical value in the list, but there is no individual block that removes an item (or multiple items) which contains a specified string from a list. This tutorial will show how to remove an item from a list based on the string stored within the item.

Project Situations

There could be a number of purposes why one would need to remove an item from a list based on its value (or string). The following are possible situations:

  • A list contains of items found, and the items are in random order based on when they were discovered; later, one item is given away, and the list must remove that specified item based on its name from the list.
  • A grocery list being broken down as items are bought.

Programming

The following script can be used to program this.

Note Note: This first method only removes the first instance of the specified string. The next method removes all instances of the specified string.
delete (item # of [ruby] in [gems v]) of [gems v]

This script will find the index of the first "ruby" and delete that item.


This second method removes all items that are the specified string instead of just the first:

repeat until <not <[gems v] contains [ruby]> >
delete (item # of [ruby] in [gems v]) of [gems v]
end

This script repeats deleting the first item that is "ruby" until it deletes all of the "ruby" items.