Blog

Idea - Extend the Substitute function to support the replacement of multiple words

It's difficult to build formula that replaces multiple words. Here's an idea to simplify this task by extending the Substitute function.

For text manipulation purposes, one of the core functions is Substitute. This function replaces words or characters from a given input string and the basic usage of the function looks like this:

Substitute(inputString, oldtext, newtext)
Here's a link to the official documentation:


When manipulating text in Power Apps, there's often the need to replace multiple words at the same time. There's no simple way to do this and app builders often resort to nesting multiple calls to Substitute like so:

// With this example, "Mon 1st March 2022" is the input text, 
// which typically would a dynamic value from a data source

Substitute(
Substitute(
Substitute(
Substitute(
Substitute(
Substitute(
Substitute(
"Mon 1st March 2022",
"Mon",
"Monday"
),
"Tue",
"Tuesday"
),
"Wed",
"Wednesday"
),
"Thu",
"Thursday"
),
"Fri",
"Friday"
),
"Sat",
"Saturday"
),
"Sun",
"Sunday"
)

This type of structure is difficult to write and maintain. Therefore, I suggest that it would be very helpful if the Substitute function could be enhanced to support multiple replacements. The usage would look like this:

Substitute("Mon 1st March 2022",
"Mon","Monday",
"Tue","Tuesday",
"Wed","Wednesday",
"Thu","Thursday",
"Fri","Friday",
"Sat","Saturday",
"Sun","Sunday"
)

I've added this to the ideas forum and you can vote for this feature through the link below if you also think this enhancement would be useful.

Related posts