Skip to main content

Notifications

Community site session details

Community site session details

Session Id : mj/R+aZjsR3Twoo4bDSn5N
Power Apps - Building Power Apps
Unanswered

Better way to write Substitute functions?

Like (1) ShareShare
ReportReport
Posted on 12 May 2023 16:09:30 by 526

In one of my apps, I'm passing json to a stored proc. In that json, I need to replace or remove certain special characters. Right now, I'm using the following code:

Substitute(Substitute(Substitute(txtDescription.Text, Char(10)," "), Char(34), Char(39)), Char(9), " ")

 

It's possible that I may need to account for additional characters in the future. Is there a better way to write the above code instead of nesting Substitutes? Possibly something that I could call from multiple places in my app?

Thanks

  • kriggo15 Profile Picture
    526 on 15 May 2023 at 12:30:29
    Re: Better way to write Substitute functions?

    Tried to access the Idea and vote, but it says I'm blocked for some reason.

  • kriggo15 Profile Picture
    526 on 15 May 2023 at 11:04:01
    Re: Better way to write Substitute functions?

    Sorry, but I still don't understand how that would work. Yes, I can do:

    Set(varSubstitute, Substitute(Substitute(Substitute(txtDescription.Text, Char(10)," "), Char(34), Char(39)), Char(9), " "))

    I can use this variable in the json fine. However, this variable just applies the Substitute code to the txtDescription control. How do I then apply this to TextInput1, TextInput2, TextInput3, etc. without having to change the variable each time?

  • timl Profile Picture
    34,988 Super User 2025 Season 1 on 12 May 2023 at 22:07:25
    Re: Better way to write Substitute functions?

    For info, I agree that it's awkward to substitute multiple words.

    Here's an idea that I posted about a year ago above improving the Substitute function.

    https://ideas.powerapps.com/d365community/idea/a5591230-ee41-4914-b22e-b0f98811298b

     

  • turnerj3 Profile Picture
    2,039 on 12 May 2023 at 18:06:32
    Re: Better way to write Substitute functions?

    We can make that work.

    Set one variable at the start of your app that is the substitute code. Use the same variable in each of your text boxes. That way you only change it in one place.

    Set(varSubstitute, YourSubstituteCode)

  • kriggo15 Profile Picture
    526 on 12 May 2023 at 18:02:02
    Re: Better way to write Substitute functions?

    Thank you, though I'm not sure that would work for my situation. One screen, I have 5 text input boxes and I want to apply the same code to each box. I prefer not to set a variable for each of those and in the future, I'd like to be able to just change the formula in one place and it cascade to each place it is used if possible.

  • turnerj3 Profile Picture
    2,039 on 12 May 2023 at 17:57:42
    Re: Better way to write Substitute functions?

    This is an example of what I did yesterday in the OnStart property of my app.

    Could be done with a button, OnVisible, Onchange, etc.

    I was creating a url string based on the users email address and having to substitute special characters with underscores.

     

    Set(varLink, Substitute(User().Email,"@","_"));
    Set(varLink, Substitute(varLink,".","_"));
    Set(varLink, Concatenate("Whatever", varLink))

  • kriggo15 Profile Picture
    526 on 12 May 2023 at 17:49:07
    Re: Better way to write Substitute functions?

    Could you provide an example? In my above code, I'm applying it to textDescription.Text. But I may want to apply the same function to other TextInput fields.

  • turnerj3 Profile Picture
    2,039 on 12 May 2023 at 17:20:34
    Re: Better way to write Substitute functions?

    You can set a variable with the substitute function and keep changing the variable with substitutes instead of nesting.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
MS.Ragavendar Profile Picture

MS.Ragavendar 20

#2
BCBuizer Profile Picture

BCBuizer 10 Super User 2025 Season 1

#2
LC-26081402-0 Profile Picture

LC-26081402-0 10

Overall leaderboard
Loading started