cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
NigelP
Kudo Kingpin
Kudo Kingpin

Substitute Function Confusion

Hi

 

Looking through the responses for the Substitute function.  It looks as if you have subsititute function in a "On Select" of a Button you must use Set(varfirstSubstitution,Substitute(<original string>,<string to replace>,<replacement string>)) and varfirstSubstitution holds the updated string.

 

If you use the substitute function elsewhere the Substitute(<original string>,<string to replace>,<replacement string>) and <original string > has been updated.

 

Am I correct ?

 

Thanks

 

Nigel

2 ACCEPTED SOLUTIONS

Accepted Solutions
rubin_boer
Super User
Super User

hi @NigelP the original string both cases should not change. if you have a variable "Some string" when you substitute the string whether onselect or in a label the variable will remain, substitute give you a new output. this is my understanding,

 

have la look at this

Set(_String,"This is a string") and assign the variable to a label

 

rubin_boer_0-1613668894655.png

Substitute the string  Set(_SubstitudedString, Substitute(_String,"string","what")) and assing the variable to anopther label

 

the add both variable to a single label, you can see the _String variable remains unchanged.

 

Is you rexpereince different?

 

Hope this helps

 
 

View solution in original post

RandyHayes
Super User
Super User

@NigelP 

Substitute is a Function that returns a substituted string.  It does not alter the original string.

If you use substitute on a non-behavioral property (for example, the Text property of a label), it will use the results of the function.

Example - a Label Text property:  Substitute("My Dog is Brown", "Dog", "Horse") will display My Horse is Brown in the label.

If you use Substitute in a behavioral action (an OnSelect for example), then this implies you are going to do something with it.

Example:   Set(myVar,  Substitute("My Dog is Brown", "Dog", "Horse") )  will give you a variable with  My Horse is Brown in it.

 

Also worth noting, substitute can be chained (as with almost all functions in PowerApps).  So the following in a Label Text property:

    Substitute(Substitute("My Dog is Brown", "Dog", "Horse"), "Brown", "White")

would display My Horse is White

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
rubin_boer
Super User
Super User

hi @NigelP the original string both cases should not change. if you have a variable "Some string" when you substitute the string whether onselect or in a label the variable will remain, substitute give you a new output. this is my understanding,

 

have la look at this

Set(_String,"This is a string") and assign the variable to a label

 

rubin_boer_0-1613668894655.png

Substitute the string  Set(_SubstitudedString, Substitute(_String,"string","what")) and assing the variable to anopther label

 

the add both variable to a single label, you can see the _String variable remains unchanged.

 

Is you rexpereince different?

 

Hope this helps

 
 
RandyHayes
Super User
Super User

@NigelP 

Substitute is a Function that returns a substituted string.  It does not alter the original string.

If you use substitute on a non-behavioral property (for example, the Text property of a label), it will use the results of the function.

Example - a Label Text property:  Substitute("My Dog is Brown", "Dog", "Horse") will display My Horse is Brown in the label.

If you use Substitute in a behavioral action (an OnSelect for example), then this implies you are going to do something with it.

Example:   Set(myVar,  Substitute("My Dog is Brown", "Dog", "Horse") )  will give you a variable with  My Horse is Brown in it.

 

Also worth noting, substitute can be chained (as with almost all functions in PowerApps).  So the following in a Label Text property:

    Substitute(Substitute("My Dog is Brown", "Dog", "Horse"), "Brown", "White")

would display My Horse is White

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,226)