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
Tried to access the Idea and vote, but it says I'm blocked for some reason.
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?
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
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)
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.
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))
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.
You can set a variable with the substitute function and keep changing the variable with substitutes instead of nesting.
MS.Ragavendar
20
BCBuizer
10
Super User 2025 Season 1
LC-26081402-0
10