AddRemoveListItem ( theList ; value )
Rate this function: Average rating: 3.8 (15 votes) Discuss this Custom Function
David Head, uLearnIT
http://www.ulearnit.com.au/
Add a value to or remove an values from a list of values
Sample Input:
| AddRemoveListItem ( "apple¶banana¶cherry" ; "banana" ) |
|
Sample Output:
|
Description:
This function will add an item to a list if it does not already exist; otherwise the item is removed from the list.
Update: the listminusitem was adjusted to account for instances where the value being removed is also the end of any value of the list. This now works by wrapping the list in double ¶, substituting out the value, and finally substituting out the double ¶ at the end. Also reversed the logic of the item test (novalue). Also now consistent about referring to "value" instead of "item" in all variables.
Further update: added substitution of three ¶ to ensure that when the very last value is removed, the list is null. Thanks to Andrew McCallum.
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:5 most recent comments | Show all 6 comments Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:
|
Newest Custom Functions:
| 1. |
GeoBox(latitude;longitude; radius) |
| |
(Mon, Mar 15, 11:04am) |
| 2. |
MonthNameList ( start; number; short ) |
| |
(Sun, Mar 14, 11:45pm) |
| 3. |
matchListAB( ListA ; ListB; match_Value; match_operator ; getN ) |
| |
(Sun, Mar 14, 10:29pm) |
| 4. |
Bin2Hex ( binary ) |
| |
(Sat, Mar 13, 10:08pm) |
| 5. |
SlideView (text) |
| |
(Sat, Mar 13, 8:40pm) |
| 6. |
HashFNV1a64 ( text ; empty ) |
| |
(Sat, Mar 13, 6:23pm) |
| 7. |
HashFNV1a32 ( text ; empty ) |
| |
(Sat, Mar 13, 5:55pm) |
| 8. |
XORbin( bin0 ; bin1 ; "" ) |
| |
(Sat, Mar 13, 4:35pm) |
 |
|
How about:
Let (
nope = IsEmpty ( FilterValues ( theList ; value ) ) ;
If ( nope ;
List ( theList; value );
Substitute( theList & ¶; value & ¶; "" )
)
)
Bruce Robertson, Redmond WA
March 09, 2009 10:57am