Domino Code Fragment

Code Name*
generic @Replace
Date*
12/29/2001
Source (or email address if you prefer)*
zp@arcor.de
IP address:.212.144.150.226
Description*
this function @Replace all list elements starting with given prefix
Type*
Formula
Categories*
List Processing/Sorting
Implementation:
None (plug and play)
Required Client:
(none)
Server:
(none)
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
ListA:="applepie" : "orangejuice" : "bananasplit" : "pear tree";
ListB:="pear" : "apple";
Results:=@Replace(ListA;ListB*+@ReplaceSubstring(ListA;ListB;"");"");
REM "Results are: orangejuice; bananasplit";
REM "That's all.";
REM " ";
REM "To see why this works, here the steps of evaluation:";
REM "To have @Replace find all elements to replace, ";
REM "you have to permute ListB with all possible RightPart strings found in ListA.";
REM "This RightPart list is built by @ReplaceSubstring:";
RightPartList:=@ReplaceSubstring(ListA;ListB;"");
REM "RightPartList is: pie; orangejuice; bananasplit; tree";
REM "Now this RightPartList is permuted with ListB to the ReplaceList:";
ReplaceList:=Listb*+RightPartList;
REM "ReplaceList is: pearpie; pearorangejuice; pearbananasplit; pear tree; applepie; appleorangejuice; applebananasplit; apple tree";
REM "Because elements like 'pearpie' not found in ListA do not disturb @Replace,";
REM "only matching elements from ReplaceList are changed in ListA:";
Result:=@Replace(ListA;ReplaceList;"");
REM "Result is: orangejuice; bananasplit";
Result