Ultimate Power Automate Substring Function Explained – 6 Powerful Examples

If you have ever needed to extract part of a string in your flow, this tutorial will guide you through the Ultimate Power Automate Substring Function Explained with step-by-step examples. Whether you’re building automation for email parsing, document naming, or text extraction, the substring function will quickly become one of your most useful tools in Power Automate.

In this tutorial, we’ll explore 6 variations of substring so you can master text manipulation in your flows.

🧰 Prerequisites

Before we dive into the examples, make sure you have:

  • A Microsoft 365 account with access to Power Automate
  • Basic knowledge of creating a flow
  • Familiarity with expressions in Power Automate
Substring Function Explained

πŸš€ Step-by-Step Examples

For our examples, we’ll use the same input string stored in a variable:

Input Text:
The quick brown fox jumps over the lazy dog

🦊 Fun Fact:
β€œThe quick brown fox jumps over the lazy dog” is a pangram β€” a sentence that contains all 26 letters of the English alphabet at least once.

πŸ”Ή 1. Substring by Start Index + Length

Extract a portion of text by providing a starting index and length.
The index represents the position of the character where you want the substring to start, and from that point it will extract text based on the specified length.

In the expression below, we are using:

  • Text: coming from the variable variables('Input Text')
  • Index: set to 4 (the starting position of the substring)
  • Length: set to 5 (the number of characters to extract)

Expression:

substring(variables('Input Text'), 4, 5)

Output:
quick


πŸ”Ή 2. Substring by Start Index + End Index

Here, we calculate the length dynamically by subtracting the end index from the start index.

  • To perform subtraction, we use the sub function.
  • For this, you need to know both the start index (16) and the end index (19).

Expression:

substring(variables('Input Text'), 
   16, 
   sub(19,16))

Output:
fox


πŸ”Ή 3. Substring by Start Marker + End Marker

This approach is useful when you don’t know the exact index but do know the surrounding text markers-for example, “jumps” and “lazy”. In this case, we calculate the start index and end index using these markers.

Expression:

substring(variables('Input Text'),
   indexOf(variables('Input Text'),'jumps'),
   sub(indexOf(variables('Input Text'),'lazy'),
       indexOf(variables('Input Text'),'jumps')))

Output:
jumps over the

Note: When using this method, be careful with your chosen markers. If the end marker appears before the start marker, the expression will throw an error. For example, using “the” as the end marker will fail because it occurs earlier in the text (before “jumps”). Even if the marker appears multiple times, Power Automate will pick the first occurrence it finds.

βœ… Safer Approach:
If you know your end marker appears multiple times and you want the last occurrence, use the lastIndexOf() function instead of indexOf().


πŸ”Ή 4. Substring from Start Index Until End

If you only specify the start index and calculate length until the end of the string, you can capture the rest of the text.

Expression:

substring(variables('Input Text'),
   31,
   sub(length(variables('Input Text')),31))

Output:
the lazy dog


πŸ”Ή 5. Substring from Start to Midpoint

You can also take the first half of a string by dividing its length in half.

Expression:

substring(variables('Input Text'),
   0,
   div(length(variables('Input Text')),2))

Output:
The quick brown fox j

This method uses the length() function to calculate the total length of the text, then divides it by 2 using the div() function to find the midpoint index.


πŸ”Ή 6. Substring from Midpoint to End

You can also extract the last half of a string by starting from the midpoint and continuing until the end.

Expression:

substring(variables('Input Text'),
   div(length(variables('Input Text')),2),
   sub(length(variables('Input Text')),
       div(length(variables('Input Text')),2)))

Output:

umps over the lazy dog


πŸ“ˆ Why This Matters

The Ultimate Power Automate Substring Function Explained tutorial demonstrates how flexible text manipulation can be. Whether you need to parse file names, extract IDs from an email subject, or trim unwanted text, substring gives you precise control over your data.


βœ… Wrapping Up

Now you’ve seen the Ultimate Power Automate Substring Function Explained with 6 practical variations. These examples will help you handle different scenarios where you need text extraction in your flows.

πŸ‘‰ Try experimenting with different markers, indexes, and dynamic values in your own Power Automate solutions.

 πŸš€ Bonus tutorials:

Leave a Comment