![]() |
PING
0.9
Statistical data handling and processing in production environment
|
Find and replace all the occurrences of (an) element(s) in a list.
list : a list of blank separated strings;old : (list of) string(s) defining the pattern(s)/element(s) to replace for in the input list list;new : (list of) string(s) defining the replacement pattern(s)/element(s) in the output list rlist; this list must be of length 1 or same length as old;startind : (option) specifies the index of the item in list at which the search should start; incompatible with option startind above; default: startind, i.e. it is not considered;startpos : (option) specifies the position in list at which the search should start; default: startpos=1; incompatible with option startind above; default: startpos, i.e. it is not considered;casense : (option) boolean flag (yes/no) set to perform cases sensitive search/matching; default: casense=no, i.e. all lower- and upper-case occurrences of the pattern in old will be replaced;sep : (option) character/string separator in input list; default: %quote( ), i.e. sep is blank.rlist : output list of indexes where all the elements of old present in list have been replaced by the corresponding elements in new (i.e. in the same position in both old and new lists).
Let us consider a simple example:
which returns rlist=NL UK FR IT FR BE FR.
Run macro %_example_list_replace for more examples.
old and new of lengths n and m respectively:n=1 and m>=1: all the occurrences of the single item present in old will be replaced by the list new, orm=1 and n>=1: items in list old will be all replaced by the single item in new, orn=m: the ith item of old will be replaced by the ith item of new; otherwise, when n ^= m, an error is reported. with both old and new of same length, one should verify that for:
the following equality holds: list_index(&rlist, &ind) = &olist.
%list_find, %list_index, %list_remove, %list_count, %list_length, FIND.