Wildcards not an option in RemoveFromList?
pmazzoni
I have a list, selWavesList, of wave names created with wavelist("*", ";", ""). I would like to remove from this list all names that contain a user-entered string. For example:
selWavesList = "Freeze_Duration_DM;Freeze_Duration_DM_v2;Freeze_Duration_DM_v3"
I want to remove all items with "DM_", which in this case are the second and third items in the list. The desired result is "Freeze_Duration_DM". I was hoping that the following would work:
selWavesList = removeFromList("DM_*", selWavesList)
...but it does not. The list remains unchanged. Is removeFromList limited to removing one item at a time, or am I using the wildcard incorrectly?
I don't think you can use wildcards in RemoveFromList. Have a look at GrepList which supports regular expressions.
February 11, 2024 at 08:41 am - Permalink
// Wildcards okay! Case insensitive.
function/S RemoveFromListWC(string listStr, string zapListStr)
string removeStr = ""
int i
for (i=ItemsInList(zapListStr)-1;i>=0;i-=1)
removeStr += ListMatch(listStr, StringFromList(i, zapListStr))
endfor
return RemoveFromList(removeStr, listStr, ";", 0)
end
February 11, 2024 at 09:35 am - Permalink
print GrepList(selWavesList, "DM_" ,1 )
> Freeze_Duration_DM;
February 11, 2024 at 01:51 pm - Permalink
Thank you Tony and Ilavsky!
February 11, 2024 at 07:03 pm - Permalink