Live Developer Training: next batch coming soon. Be the first to know.Live training: next batch soonJoin the waitlist →Join →

Replace in Power Apps | PowerApps Replace Character in String

In this Power Apps article, I will tell you what the PowerApps replace function is, how to use Power Apps replace function, and how to substitute in Power Apps with various examples.

Also, we will discuss how to work with Power Apps replace character in string, Power Apps remove special characters from string, and many more like:

  • Power Apps Replace Space
  • Power Apps Find and Replace Character in String
  • Working with Power Apps Replace Double Quotes
  • How to use PowerApps Replace Line Break

Replace Function in Power Apps

Power Apps Replace function helps to identify the string to replace by starting position and length. Below are the Power Apps 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’s 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:

Suppose 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

Substitute Function in Power Apps

Power Apps 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 are the Power Apps Substitute function syntaxes:

Syntax-1:

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

Where,

  • 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 optional. If String contains more than one instance of OldString, use this argument to specify which instance to replace. Otherwise, all instances will be replaced

Syntax-2:

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

Where,

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

Power Apps Replace Character in String

In Power Apps, if you want to replace a character in a string, follow the simple examples below.

1. Power Apps Replace a Single Character in String

Suppose you want to replace the second character [“e”] in “Hello” with another character [“a”]; you can follow the below two codes.

1. Text = Replace("Hello", 2, 1, "a" )
replace in powerapps
2. Text = Substitute("Hello", "e", "a" )
substitute in powerapps

2. Power Apps Replace Multiple Characters in String

If you want to Replace four characters in “Johannal” with a single “#” character, starting with the second character (“o”), Refer to the code below.

Text = Replace("Johannal", 2, 4, "#" )
replace function in powerapps

Also, you can use the code below to replace multiple occurrences in “power platform” [p->P].

Text = Substitute("power platform", "p", "P")
powerapps replace function

3. Power Apps Replace a Substring in String

Suppose you want to substitute a substring in the text [Sales Products], such as substituting the string “Cost” for “Product.” Follow the code below.

Text = Substitute( "Sales Product", "Product", "Cost" )