PowerApps Replace Function with examples

 

 

Also, by taking some simple scenarios, we will cover these below topics as:

  • PowerApps Substitute function
  • PowerApps Replace and Substitute function Examples
  • PowerApps replace all character in string
  • PowerApps remove special characters from string
  • PowerApps replace double quotes
  • PowerApps substring
  • PowerApps replace space
  • PowerApps replace data source
  • PowerApps replace Line break
  Table of Contents  show

PowerApps Replace function

Powerapps Replace function helps to identify the string to replace by starting position and length. Below represents the Powerapps Replace function syntaxes:

Syntax 1:

 
Replace( String, StartingPosition, NumberOfCharacters, NewString )

Where,

  • String = This is the required field that defines the string to operate on.
  • StartingPosition = This is the Character position to start the replacement. The first character of String is at position 1.
  • NumberOfCharacters = The number of characters to replace in String.
  • NewString = This is the replacement string. The number of characters in this argument can differ from the NumberOfCharacters argument.
 

Syntax 2:

If you pass a single-column table that contains texts, the return value is a single-column table of modified strings. If you have a multi-column table, you can shape it into a single-column table.

Replace( SingleColumnTable, StartingPosition, NumberOfCharacters, NewString )

Where,

  • SingleColumnTable = A single-column table of strings to operate on. This is a required field.

You may like Customize SharePoint List form using PowerApps and How to use PowerApps forall function.

PowerApps Substitute function

Powerapps Substitute function helps to identify the string to replace by matching a string. You can replace the text if more than one match is found. Below represents the Powerapps Substitute function syntaxes:

<iframe data-google-container-id="5" data-load-complete="true" frameborder="0" height="1" id="google_ads_iframe_/18190176/AdThrive_Content_3/5eb0521be9893f1f1a5bfca4_0" marginheight="0" marginwidth="0" name="google_ads_iframe_/18190176/AdThrive_Content_3/5eb0521be9893f1f1a5bfca4_0" scrolling="no" title="3rd party ad content" width="1"></iframe>

Syntax 1:

Substitute( String, OldString, NewString [, InstanceNumber ] )
  • String = This is the required field that defines the string to operate on.
  • OldString = This is the required field that defines a string to replace.
  • NewString = The replacement string. OldString and NewString can have different lengths.
  • InstanceNumber = This is an optional. Use this argument to specify which instance of OldString to replace if String contains more than one instance. All instances will be replaced if you don’t specify this argument.

Syntax 2:

Substitute( SingleColumnTable, OldString, NewString [, InstanceNumber ] )

Where,

  • SingleColumnTable = A single-column table of strings to operate on.

Read: Power Apps Button OnSelect

 

PowerApps Replace and Substitute function Examples

Below table represents some simple PowerApps Replace and Substitute function formulas, Description and its Output.

Formula Description Output
Replace(“Preetisahu”, 2, 5, “#” ) Replaces five characters in “Preetisahu” with a single “#” character, starting with the second character (“r”). “P#sahu”
Replace(“2021”,3,2, “19”) Replaces the last two characters of “2021” with “19”. “2019”
Replace( “658712”, 1, 3, “_” ) Replaces the first three characters of “658712” with a single “_” character. “_712”
Substitute( “Sales Product”, “Product”, “Cost” ) Substitutes the string “Cost” for “Product”. “Sales Cost”
Substitute( “Quarter 1, 2018”, “1”, “2”, 1 ) Substitutes only the first instance of “1” with “2” because the fourth argument (InstanceNumber) is provided with a 1. “Quarter 2, 2018”
Substitute( “Quarter 1, 2011”, “1”, “2”, 3 ) Substitutes only the third instance of “1” with “2” because the fourth argument (InstanceNumber) is provided with a 3. “Quarter 1, 2012”
Substitute( “Quarter 2, 2021”, “2”, “3” ) Substitutes all instances of “2” with “3” because the fourth argument (InstanceNumber) isn’t provided. “Quarter 3, 3031”
Replace(
[ “Quarter 2, 2018”,
“Quarter 4, 2011”,
“Quarter 5, 2019” ],
9, 1, “3” )
Replaces the ninth character in each record of the single-column table with “3”. [ “Quarter 3, 2018”,
“Quarter 3, 2011”,
“Quarter 3, 2019” ]
Substitute(
[ “Qtr 1, 2018”,
“Quarter 1, 2011”,
“Q1, 2019” ],
“1”, “3”, 1 )
Because the fourth argument (InstanceNumber) is provided with a value of 1, substitutes only the first instance of “1” in each record of the single-column table with “3”. [ “Qtr 3, 2018”,
“Quarter 3, 2011”,
“Q3, 2019” ]
Substitute(
[ “Qtr 2, 2028”,
“Quarter 2, 2022”,
“Q2, 2029” ],
“2”, “3” )
Because the fourth argument (InstanceNumber) isn’t provided, substitutes all instances of “2” in each record of the single-column table with “3”. [ “Qtr 3, 2038”,
“Quarter 3, 2033”,
“Q3, 2039” ]
 

PowerApps Replace String

PowerApps Replace String helps to replace a portion of a string of text with another string. Suppose we need to replace any text in the Powerapps form, then we can use the Replace keyword.

PowerApps Replace String and PowerApps Replace Function both are the same. We are using the Powerapps Replace function to replace a string. Follow these below examples to understand easily.

You may like PowerApps submit form to SharePoint Online list.

PowerApps replace all character in string

  • Here we will see how to use PowerApps to replace all characters in the string. In this example what I want to do is, I have a PowerApps Edit form that I need users to fill out.
  • In the below screenshot, you can see there’s a text input field (Customer Contact Number) from the form where I would like to block every “” character that is entered in it.
  • For example, if someone enters a mobile number like “32-39-60-71-25”, then I want that the text input field from the form to convert that into “3239607125”.
  • To do this, We need to use the PowerApps Substitute() function. Select the Data card (Customer Contact Number) and apply this below formula on its Update property as:
Update = Substitute(
    DataCardValue8.Text,
    "-",
    ""
)
 

Where,

  • DataCardValue8 = Customer Contact Number Data Card Name
  • “-“ = Here, I want to block every “-” character that is entered in it in the text input field and replace with a blank value.

You can refer the below screenshot.

PowerApps Replace Function with examplespowerapps replace function  
  • Now Save and Preview (F5) the Powerapps edit form. Enter the fields including the Customer Contact Number field (with “-“) and then submit the form.
PowerApps Replace Function with examples
  • Once the Powerapps form is submitted, go to your specific SharePoint list or Excel sheet where you are storing the data. There, you can view the Customer Contact Number that has been stored excluding the “-” as shown in the below screenshot.
PowerApps Replace Function with examplespowerapps replace function  

PowerApps remove special characters from string

In this scenario, We will discuss how to remove special characters from string or how to validate a field for the special character in PowerApps. Let’s take a simple scenario for better understanding.

  • In PowerApps, there are few fields in which I want to validate one field from those. If a user enters a special character (like \, *, #, etc.), then the form will not submit and it will show a warning message.
  • For warning message, I can use the Powerapps Notify function that will act if the field value consisting of a special character or not.
  • First of all, Set the OnChange property of the Text input control data card value by given below formula:
OnChange = IsMatch(DataCardValue9.Text,".*[\\\"&Char(34)&"].*")

Where,

DataCardValue9.Text = Text input control name

PowerApps Replace Function with examplesPowerApps remove special characters from string  
  • For warning the user for invalid characters, Take a Label input control and apply the below formula on its Textand Visible property as:
Text = "Special characters are not allowed!"
PowerApps Replace Function with examplesPowerApps remove special characters from string
Visible = IsMatch(DataCardValue9.Text,".*[\\\"&Char(34)&"].*")

PowerApps Replace Function with examplesPowerApps remove special characters from string example

 
  • Then go to the Submit button and set the DisplayMode property as below:
DisplayMode = If(
    !Label1.Visible,
    Edit,
    Disabled
)

Where,

Label1 = Label input control name

PowerApps Replace Function with examplesPowerApps remove special characters from string

  • Now Save and Preview (F5) the app. Enter the text (in the text input control) including the special character “\” (As I have mentioned the special character in my example are “\” and double quote, but you can replace it with yours).
  • Once you will enter the text with the special character, then you can see a warning message will appear (in the label control), and also at the same time, the Submit button will also disable as shown below. 
 

PowerApps Replace Function with examplesPowerApps remove special characters from string

You may like PowerApps AddColumns Function with Examples.

PowerApps replace double quotes

In this example, We will check how to work with PowerApps replace double quotes.

  • Suppose you have a Label input control and inside the label control, you want to display the string as like “POWERAPPS” (with double quote).
  • For this, I tried the formula as “”POWERAPPS”” (on the Label Text property), but it doesn’t work for me. You can see the below screenshot for your reference:
PowerApps Replace Function with examplesPowerApps replace double quotes  
  • Check these below formula to get the solution:
Text = Char(34) & "POWERAPPS" & Char(34)

Where,

“PowerApps” = Specify a string that you want to display in the label control.

  • Double quotes within PowerApps has different meaning other than the character. If you want to display a character in Text, we could take use of the Char() function, which would translates a character code into a string. Follow this below screenshot.
PowerApps Replace Function with examplesPowerApps replace double quotes  

PowerApps Substring

To find out the Substring from a string, we can use PowerApps LeftMid and Right functions.

  • PowerApps Left function extracts the starting characters of a string.

Syntax:


Left( String, NumberOfCharacters )

Where,

  1. String = This is the required field that helps the string from which to return the result.
  2. NumberOfCharacters = This is also a Required field (Left and Right only). The number of characters to return. If omitted for the Mid function, the function returns the portion from the starting position until the end of the string.
  • PowerApps Mid function extracts the middle characters of a string.

Syntax:

 
Mid( String, StartingPosition [, NumberOfCharacters ] )

Where,

  1. StartingPosition = This is the required field for Mid only. The starting position. The first character of the string is position 1.
  • PowerApps Right function extracts the ending characters of a string.

Syntax:


Right( String, NumberOfCharacters )

For Single Column Table: 

Syntax:

  1. For Left function:
Left( SingleColumnTable, NumberOfCharacters )
 

2. For Mid function:

Mid( SingleColumnTable, StartingPosition [, NumberOfCharacters ] )

3. For Right function:

Right( SingleColumnTable, NumberOfCharacters )

Where,

  • SingleColumnTable = This is a required field. A single-column table of strings from which to return the results.
  • StartingPosition = This is also required (Mid only). The starting position. The first character of the string is position 1.
  • NumberOfCharacters = This is the required field (Left and Right only). The number of characters to return. If omitted for the Mid function, the function returns the portion from the starting position until the end of the string.

To learn more details about the PowerApps Left, Mid, and Right function, you can follow this tutorial: PowerApps Left, Mid, and Right function

PowerApps replace space

In this scenario, We will see how to replace a space in PowerApps.

  • In Powerapps, I have a Text input control and a Label control.
  • A user will enter any text or number into the input field including some spaces. But I want to remove the space from the text and the result will display in the Label control.
  • For that, I am using this formula on the Text property of the Label input control as:
Text = Substitute(TextInput2.Text," ","")

Where,

TextInput2 = This is the input control where a user will enter the string or text.

PowerApps Replace Function with examplesPowerApps replace space

PowerApps replace data source

  • Suppose you want to change or replace the Data source in Powerapps. In this case, first, you need to remove the old Data source and then add the new one.
  • As long as the data source name is not changed in PowerApps, and its status is connected, then the formulas will continue to use this old name and connect to the source correctly.
  • To remove the old data source from the Powerapps, 
    • Go to View tab -> Click on Data Sources -> Select … from Data source that you want to remove -> Click on Remove as shown below.
PowerApps Replace Function with examplesPowerApps replace data source
  • Similarly, to add the new Powerapps Data source, follow these below things:
    • Go to View -> Data sources -> Connectors -> Search SharePoint -> Add a new or existing connection.
    • Choose the specific SharePoint Site and select the SharePoint List that you want to connect and hit on the Connect button. Now the SharePoint list will connect to the Powerapps app.
  • One thing you must remember is, Whenever you are changing the data source to the new one, then change the data sources of the controls to the new connection including all the formulas.
  • Another thing is, When you are changing the data source, it may affect all the fields and at the same time, the new fields will add from the SharePoint list.

PowerApps replace Line break

Here, We will see how to remove the End of Line character from a string.

As you know, We are using “/br” code to break a line or sentence in HTML. Similarly, in the Powerapps, We can use the character code as “Char(10)” for a line break. Let’s take a simple example.

  • In PowerApps, I have a Text input control (multiline) and a Label input control.
  • I want to remove multi-line from a string, so I need to strip out the end of line character and have it all one line. For delimitation, We can add a comma.
  • All the output I need to display in the label control. So select the Label control and apply this below formula on it’s Text property as:
Text = Substitute(TextInput2.Text,Char(10),",")

Where,

  1. TextInput2.Text = Text input control name
  2. Char(10) = This is the character code for line breaking
  3. “,” = It is the delimit that I want to add

NOTE:

Not only you can use only the text input control (multiline), but also you can use the HTML text input control in Powerapps. You can use the above formula on the HTML Text property of the HTML Text input control.
PowerApps Replace Function with examplesPowerApps replace Line break
  • Now Save and Preview (F5) the app. Enter multi-text in the Text input control (multiline) as in the below screenshot. The result will appear in the Label control without a break including a delimiter “,”.
PowerApps Replace Function with examplesPowerApps replace Line break

You may like these below Powerapps Tutorials as:

In this Powerapps tutorial, we learned how to use PowerApps Replace function with a few examples, Powerapps Replace string, and its syntaxes. Also, by taking some simple scenarios, we covered these below topics as:

  • PowerApps Substitute function
  • PowerApps Replace and Substitute function Examples
  • PowerApps replace all character in string
  • PowerApps remove special characters from string
  • PowerApps replace double quotes
  • PowerApps substring
  • PowerApps replace space
  • PowerApps replace data source
  • PowerApps replace Line break
上一篇:拆解PowerApps - 请假申请 -10


下一篇:PowerApps Component Framework PCF 初始化