cancel
Showing results for 
Search instead for 
Did you mean: 

Substitute function - add the ability to substitute multiple words

To replace multiple words from an input string, there's no easy way to carry out this task except to nest multiple calls to Substitute function like so:

 

Set(varInputString, "Mon 1st March 2022")

 

 

 

Substitute(
    Substitute(
        Substitute(
            Substitute(
                Substitute(
                    Substitute(
                        Substitute(
                            varInputString,
                            "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 helpful if the Substitute function could be enhanced to support multiple replacements. The enhanced usage would look like this:

 

 

Substitute(varInputString,
            "Mon","Monday",
            "Tue","Tuesday",
            "Wed","Wednesday",
            "Thu","Thursday",
            "Fri","Friday",
            "Sat","Saturday",
            "Sun","Sunday"
)

 

 

If it's difficult to extend the Substitute function due to the use that includes the optional 'InstanceNumber' argument, I would propose a new function called SubstituteMultiple to carry out this task.

Many thanks for your consideration.

Status: New
Comments
DDCJOEE
Advocate III

This would be incredibly valuable. I have a lot of apps that do in-depth string manipulation, and I've written those nested substitute functions so many times. It is a pain. This solution makes a lot of sense! 

metsshan
Solution Sage

I would like to see this added.

 

My use case is a Template Editing screen where property placeholder string parts are included in the message, then replaced with actual values in a "Preview" text box.