其他分享
首页 > 其他分享> > PowerApps Replace Function with examples

PowerApps Replace Function with examples

作者:互联网

 

 

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

  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,

 

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,

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 ] )

Syntax 2:

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

Where,

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

Update = Substitute(
    DataCardValue8.Text,
    "-",
    ""
)
 

Where,

You can refer the below screenshot.

PowerApps Replace Stringpowerapps replace function   Replace String in PowerApps PowerApps Replace functionpowerapps 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.

OnChange = IsMatch(DataCardValue9.Text,".*[\\\"&Char(34)&"].*")

Where,

DataCardValue9.Text = Text input control name

PowerApps remove special characters from stringPowerApps remove special characters from string  
Text = "Special characters are not allowed!"
PowerApps remove special characters from a stringPowerApps remove special characters from string
Visible = IsMatch(DataCardValue9.Text,".*[\\\"&Char(34)&"].*")

PowerApps remove characters from a stringPowerApps remove special characters from string example

 
DisplayMode = If(
    !Label1.Visible,
    Edit,
    Disabled
)

Where,

Label1 = Label input control name

PowerApps remove characters from stringPowerApps remove special characters from string

 

PowerApps remove characters from the stringPowerApps 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.

PowerApps replace double quotesPowerApps replace double quotes  
Text = Char(34) & "POWERAPPS" & Char(34)

Where,

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

PowerApps replace double quotePowerApps replace double quotes  

PowerApps Substring

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

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.

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.

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,

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.

Text = Substitute(TextInput2.Text," ","")

Where,

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

PowerApps replace spacePowerApps replace space

PowerApps replace data source

PowerApps replace data sourcePowerApps replace data source

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.

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 Line breakPowerApps replace Line break PowerApps replace Line breakingPowerApps 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:

标签:Function,function,PowerApps,string,character,replace,control,examples
来源: https://www.cnblogs.com/lingdanglfw/p/14875785.html