How to remove characters from string in Power Automate? [with examples]

In this flow tutorial, we will be learning how to remove characters and letters from strings in Power Automate with examples and we will also be looking at different substring and replace functions including the below topics.

  1. Power Automate replace strings
  2. Power Automate replace characters from string
  3. Power Automate trim character from string
  4. Power Automate remove characters from string
  5. Power Automate remove characters from variable
  6. Power Automate remove letters from string
  7. Power Automate remove  special character from string
  8. Power Automate remove the last character from string
  9. Power Automate remove the first character from string
  10. Power automate remove first and last characters from string
  11. Power Automate remove  multiple characters from string
  12. Power Automate remove last n characters from string

Power Automate replace strings

Let’s start this tutorial by learning how to replace a string using Power Automate Flow.

Replace() function identifies the text and replaces every occurrence of a given text with the substitute in Power Automate.

Here is the syntax of replace() function in Power Automate:

replace( Text , OldString , SubstituteString )

We will start by creating a flow that we trigger manually and after that, we will initialize the variable ‘myteststring‘ and set the data type as ‘string‘ and the value with the text ‘Chicago is the best city‘ shown in the below image.

Power Automate replace strings Initialize Variable
Initialize Variable in Power Automate

After initializing the variable, we will use the Compose action to replace the string value of the variable ‘myteststring‘ and then will send the modified string value in an email using Send an email action

Power Automate replace strings
Power Automate replace strings

We are replacing the string ‘Chicago‘ with a substitute string ‘New York‘ in the ‘myteststring‘ variable by using replace() function.

Here’s the expression:

replace(variables('myteststring'), 'Chicago','New York')
Power Automate replace strings result
Power Automate replace strings result

Once we save and run the flow, we will receive the above email with the modified text as ‘New York is the best city‘, and this is how we can replace the string in Power Automate.

Power Automate replace characters from string

After learning how to replace a string in a text, we will now learn how to replace a character from a string or text in Power Automate.

We will start by initializing a variable ‘myteststring‘ in a manually triggered flow and set the value of the variable as ‘Chicago @ the best city‘.

Our main goal here is to replace the ‘@‘ character with a string ‘is‘. To achieve this we will be using replace() function.

Power Automate replace characters from string
Power Automate replace characters from string

We are using the Compose action, to replace the ‘@‘ character with the alternative string ‘is‘ from our variable ‘myteststring‘.

Here’s the expression:

replace(variables('myteststring'), '@','is')

In this expression, we are using replace() function to modify the old text with the alternative string. We will also add Send an email action and we will use the output of the compose action in our email body.

Power Automate replace characters from string result
Power Automate replace characters from string result

As we can see, after manually running the flow we will receive the above email with the alternative text and this is how we can replace characters from a string using Power Automate.

Read Power Automate OData filter query with examples

Power Automate trim character from string

Before we dig deeper into the remove functions of Power Automate, let’s learn another important and mostly used trim function, how to trim characters from a string in Power Automate.

trim() function of Power Automate returns the string value without the leading and trailing whitespace.

We will create a manually triggered flow and initialize a variable ‘myteststring‘ with a string value ‘ Chicago City ‘ with whitespaces.

Power Automate trim character from string
Power Automate trim character from string

We will use compose action to write our trim() function expression and we will also send an email without any whitespaces. We are simply passing our variable in the trim() function as a parameter to let the function know that we want to remove whitespaces for the given string.

Here’s the expression:

trim(variables('myteststring'))
Power Automate trim character from string result
Power Automate trim character from string result

After saving and manually running the flow, we will receive the above email without whitespaces in the variable’s value and this is how we can trim a sting in Power Automate.

Power Automate remove characters from string

Let’s now learn how to remove characters from strings or text in Power Automate.

To remove any characters from string or text, we will be using the substring() function of Power Automate.

Suppose we have a static string value ‘Sample example‘ and we will start by creating a manually triggered flow and will send an email with the text but we will remove the string ‘Sample‘ and will just send the string ‘example‘ in the email body.

Power Automate remove characters from string
Power Automate remove characters from string

First, we got the length of the text ‘Sample example‘ using the length() function and then we got the index of the string ‘Sample‘ by subtracting the string length from the length of the whole string, using the Sub() function of Power Automate. Now, we have everything required of the substring() function.

Here’s the syntax of substring() function:

substring(text, startindex, lenghtofstring)

Here’s the expression:

substring('Sample example',6,sub(length('Sample example'),6))
Power Automate remove characters from string result
Power Automate remove characters from string result

After saving and manually running the flow, we will receive the above email with only the required ‘example‘ string in the email and this is how we can remove the characters from the string.

Power Automate remove characters from variable

In the above example, we have seen how to remove characters from a static string/text value in Power Automate. Let’s learn how can we remove characters from a dynamic value or a variable in Power Automate.

Suppose, we have a Sharepoint list column and we are fetching the column value in a variable, however, we only need the second string of the list column value in the email.

To achieve this, we will start by initializing the variable ‘myteststring‘ and setting the value as ‘Sample example‘ and datatype as a string shown in the below image. We will also add compose action to remove the required string using the substring() function and then we will send the output of the compose action in an email.

Power Automate remove characters from variable
Power Automate remove characters from variable

Similar to the above example, we are first getting the length of the variable and then we get the index of the string that we want to remove. Once we have all the required parameters, we will pass the parameters of the substring() function with the dynamic variable value.

Here’s the expression:

substring(variables('myteststring'),6,sub(length(variables('myteststring')),6))
Power Automate remove characters from variable result
Power Automate remove characters from variable result

We are then passing the output of the compose action into the email body of Send an email action. Once, we run the flow manually, we will receive the above email with the dynamic string variable value. This is how we can remove characters from a dynamic/static variable in Power Automate using the substring() function.

Read Microsoft flow Send an email showing wrong time for SharePoint list column

Power Automate remove letters from the string

In this section, we will learn how to remove letters from a string value in Power Automate.

Suppose, we have a Sharepoint list column with the month’s name and we would like to just send the abbreviation of the months in the email body or append the same to a filename.

We will again use the substring() function of power automate to achieve the above requirement.

We will start by initializing the variable ‘myteststring‘ with a static value, in the case of a dynamic value, we can simply pass the Sharepoint list column’s value to the variable. Next, we will add compose action from the operators and input the value with the substring() function.

The output of the compose action will then be sent to the email body of Send an email action.

Power Automate remove letters from string
Power Automate remove letters from string

In the expression, we are passing the variable as a parameter of the substring() function with the staring index of the variable and then the length of the string that we need to display.

Here’s the expression:

Power Automate remove letters from string result
Power Automate remove letters from string result

After saving and running the flow, we will receive the above email with the string value ‘Jan‘ and this is how we can remove letters from a string in Power Automate.

Power Automate remove  special character from string

Let’s learn how to remove a special character from a static or dynamic string value in Power Automate flow.

Suppose, we have a Sharepoint list column with employee email IDs however, we want to remove the special character ‘@‘ from the value using Power Automate flow and send an email with the modified employee email IDs.

We have a flow that will trigger manually, and we have initialized a variable ‘myteststring‘ with datatype as string and value ‘testuser@gmail.com‘. Next, we will add compose action to write our function, and then we add Send an email action where we will send the output of the compose action in the email body.

Power Automate removeĀ  special character from string
Power Automate remove  special character from string

In this expression, we are using replace() function to remove the “@” character from the variable with an empty string.

Here is the expression:

replace(variables('myteststring'),'@','')
Power Automate removeĀ  special character from string result
Power Automate remove  special character from string result

After manually running the flow, we will receive the above email with the string value without the “@” special character and this is how by using the replace() function we can remove a special character in Power Automate.

Read Microsoft flow change true to yes

Power Automate remove the last character from string

In this section, we will learn how to remove the last character from a string using Power Automate.

In Power Automate, we will start by initializing a variable ‘myteststring‘ with the value ‘Testing examples‘ and next we will add compose action to remove the last character ‘s‘ from the variable value and to view the result we will send this modified variable value in an email.

Power Automate remove the last character from string
Power Automate remove the last character from string

In this expression, we are using the substring() function to replace the last character ‘s‘ from the variable by passing the variable as a parameter. We are providing the starting index of the string and the index of the last character ‘s‘.

Here’s the expression:

substring(variables('myteststring'),0,sub(length(variables('myteststring')),1))
Power Automate remove the last character from string result
Power Automate remove the last character from string result

By using the substring() function, we can remove the last character from the string in PowerAutomate as shown in the above email that we receive after running the flow.

Power Automate remove the first character from string

After learning how to remove the last character from a string, let’s now learn how can we remove the first character from a string using Power Automate.

Similar to the above example, we will start by creating a flow and we will initialize a variable ‘myteststring‘ with the value ‘A testing examples‘ and datatype as a string. We will use compose action to remove the first character “A” from the variable and will verify the result by sending an email with this variable value.

Power Automate remove the first character from string
Power Automate remove the first character from string

In this expression, we are using the substring() function to replace the first character ‘A‘ from the variable by passing the variable as a parameter. We are providing the starting index of the string and the index of the first character ‘A‘.

Here’s the expression:

substring(variables('myteststring'),1,sub(length(variables('myteststring')),1))
Power Automate remove the first character from string result
Power Automate remove the first character from string result

Once we save and run the flow, we will receive the above email with the variable value without the first character “A“. And this is how easily we can remove the first character of a string in Power Automate.

Read How to get manager email or name in Microsoft Flow

Power automate remove first and last characters from string

In the above sections, we have lean how to remove the first and last character from a string, but what if there is a requirement to remove the first and the last character together from a string in Power Automate?

In Power Automate, we will start by initializing a variable ‘myteststring‘ with the value ‘@testing example@‘ and next we will add compose action to remove the first and the last character ‘@‘ from the variable value and to verify the result we will send this modified variable value in an email.

Power automate remove first and last characters from string
Power automate remove first and last characters from string

We are using the substring() function to replace the first character ‘@‘ and the last character ‘@‘ simultaneously from the variable by passing the variable as a parameter.

Here’s the expression:

substring(variables('myteststring'),1,sub(length(variables('myteststring')),2))
Power automate remove first and last characters from string result
Power automate remove first and last characters from string result

After successfully running the flow, we will receive the above email with the variable value without the first and the last characters, and using the same expression we can remove the first and last characters from the string in Power Automate.

Power Automate remove  multiple characters from string

In this section of the tutorial, we will learn to remove multiple characters from a string using Power Automate.

Similar to all the above examples, we will create a flow that will trigger manually and we will add our first step to initialize a variable called ‘myteststring‘ and set the datatype as string and value as ‘Thetest examples’.

Next, we will add compose action to remove the ‘The‘ and ‘s‘ characters from the variable and then will send the output of this action in an email body using Send an email action.

Power Automate remove multiple characters from string
Power Automate remove multiple characters from string

Here again, we are using the substring() function of Power Automate to remove the first 3 characters ‘the‘ and the last character ‘s‘ from the variable value.

We will provide the variable as a parameter in the function and then the start index will be 3 as an integer because we want to ignore the first 3 characters and then we will pass the length of the required string ‘testing example‘ by using the sub() function. In the sub() function, we passed the length of the whole string minus the last character.

Here’s the expression:

substring(variables('myteststring'),3,sub(length(variables('myteststring')),4))
Power Automate remove multiple characters from string result
Power Automate remove multiple characters from string result

Once we manually run the flow, we will receive the above email with the variable value after removing the multiple characters.

This is how we can remove multiple characters from a dynamic or static string value in Power Automate.

Read Create a Custom Document Template from SharePoint List using Microsoft Flow

Power Automate remove last n characters from string

In this final section of this tutorial, we will be learning to remove the last n characters from a string or a variable using Power Automation.

In the Power Automate flow, we will initialize our variable ‘myteststring‘ and will set the data type as string and value as ‘Chicago City‘. We will add compose action to remove the last 4 characters from the variable ‘myteststring‘ i.e ‘City‘. We will then add Send an email action to send the modified variable value in an email to verify the result.

Power Automate remove last n characters from string
Power Automate remove last n characters from string

To remove the last 4 characters or letters from the variable ‘myteststring‘, we will be using the substring() function in this expression.

We will provide the variable as a parameter in the function and then the start index will be 0 as an integer and then finally we are passing the length of the required string ‘Chicago‘ by using the sub() function.

In the sub() function, we passed the length of the whole string ‘Chicago City‘ minus the last 4 characters.

Here is the expression:

substring(variables('myteststring'),0,sub(length(variables('myteststring')),4))
Power Automate remove last n characters from string result
Power Automate remove last n characters from string result

After saving and running the flow, we will receive the above email with the required string value and this is how we can use the substring() to remove the last n characters from a string or a variable in Power Automate.

In this Power Automate tutorial, we have learned how to remove, replace, and trim characters and letters from a string value using Power Automate Flow with a few examples for understanding.

  • Power Automate replace strings
  • Power Automate replace characters from string
  • Power Automate trim character from string
  • Power Automate remove characters from string
  • Power Automate remove characters from variable
  • Power Automate remove letters from the string
  • Power Automate remove special character from string
  • Power Automate remove the last character from string
  • Power Automate remove the first character from string
  • Power automate remove first and last characters from string
  • Power Automate remove multiple characters from string
  • Power Automate remove last n characters from string

You may like the following power automate tutorials:

>