\SUBSTITUTE.ALL

Replace nested SUBSTITUTE functions with one function.

Syntax: \SUBSTITUTE.ALL(text,old_text_array,new_text_array) => text
=LAMBDA(text,old_text_array,new_text_array,
	LET(
		old_text_array, TOCOL(old_text_array),
		new_text_array, TOCOL(new_text_array),
		REDUCE(text,SEQUENCE(ROWS(old_text_array)),LAMBDA(acc,val,
			SUBSTITUTE(acc,
				INDEX(old_text_array,val),
				INDEX(new_text_array,val)
			)
		))
	)
)

Documentation

Replaces nested SUBSTITUTE statements. In the text, each element of old_text_array is replaced with the corresponding element of new_text_array

Commentary

This is popular in old tutorials as an introduction to Lambda functions. Usually seen as a recursive implementation, now obsolete with the introduction of REDUCE().

I have mixed feelings about even including this function in the library, as it is essentially trivial. It is also useful. As such, it’s included in the preview (free) version of the Premium library.


0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top