web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Better way to write Su...
Power Apps
Unanswered

Better way to write Substitute functions?

(1) ShareShare
ReportReport
Posted on 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

Categories:
I have the same question (0)
  • turnerj3 Profile Picture
    2,039 on at

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

  • kriggo15 Profile Picture
    526 on at

    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 at

    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 at

    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 at

    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)

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    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

     

  • kriggo15 Profile Picture
    526 on at

    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?

  • kriggo15 Profile Picture
    526 on at

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

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard