20 Plus String Functions in Power Automate With Real-Time Examples

20+ String Functions in Power Automate With Real-Time Examples

No comments

Loading

In this “String Functions in Power Automate or List of Functions in Power Automate” article, we will list out the list of functions in Power Automate from the string category, and we will learn about each string function in Power Automate and how each function works. We will demonstrate each function separately with a real-time example.

Power Automate, a powerful automation tool by Microsoft, is designed to help users streamline their workflows by automating repetitive tasks and integrating various apps and services. One of the key features that make Power Automate versatile is its ability to employ functions, which are essential for data manipulation, decision-making, and enhancing the overall functionality of workflows. In this comprehensive guide, we will delve into functions in Power Automate, discuss their syntax, and present real-time examples to showcase their utility and versatility.

Understanding Functions in Power Automate

In Power Automate, functions are blocks of reusable code that perform specific operations on input data and produce an output. Functions can range from simple operations like mathematical calculations to more complex actions involving strings, arrays, dates, and other data types.

Function Syntax:

In Power Automate, functions generally follow a standard syntax, consisting of a function name and one or more parameters enclosed within parentheses. The function processes the provided parameters and returns an output.

function_name(parameter1, parameter2, ...)

List of Functions in Power Automate

Following is a list of functions in Power Automate from the string category:

  • concat()
  • length()
  • replace()
  • split()
  • formatDateTime()
  • indexOf()
  • rand()
  • randBetween()
  • trim()
  • toUpperCase()
  • toLower()
  • chunk()
  • endsWith()
  • formatNumber()
  • guid()
  • slice()
  • isFloat()
  • lastIndexOf()
  • nthIndexOf()

String Functions in Power Automate: Real-time Examples Demonstrating Various Functions

Let’s explore a range of functions in Power Automate and provide real-time examples to illustrate their usage and capabilities.

Example: add() – Adding Numbers

The add() function is used to perform addition on the provided numerical values. It takes two or more numbers as parameters and returns the sum of those numbers.

Syntax:

add(number1, number2, ...)

Example:

Expression: add(5, 3)

Output:

8

Example: concat() – Concatenating Strings

The concat() function is used to concatenate multiple strings into a single string. It takes any number of strings as parameters and combines them into a single string.

Syntax:

concat(string1, string2, ...)

Example

Expression: concat('Hello, ', 'World!')

 

Output:

'Hello, World!'

Example: length() – Calculating String Length

The length() function is used to calculate the number of characters in a given string. It takes a string as a parameter and returns the length of that string.

Syntax:

length(string)

Example:

Expression: length('Power Automate')

Output:

14

Example: replace() – Replacing Substrings

The replace() function is used to replace occurrences of a specified substring within a given string. It takes the original string, the substring to be replaced, and the new substring as parameters and returns a new string with the replacements made.

Syntax:

replace(originalString, substringToReplace, newSubstring)

Example:

Expression: replace('Power Automate is powerful.', 'powerful', 'amazing')

Output:

Output: 'Power Automate is amazing.'

Example: split() – Splitting Strings

The split() function is used to split a string into an array of substrings based on a specified delimiter. It takes the original string and the delimiter as parameters and returns an array of substrings.

Syntax:

split(originalString, delimiter)

Example:

Expression: split('apple,banana,cherry,date', ',')

Output:

Output: ['apple', 'banana', 'cherry', 'date']

Example: formatDateTime() – Formatting Dates

The formatDateTime() function is used to format a date and time value according to a specified format. It takes a date and time value and a format string as parameters and returns the formatted date and time as a string.

Syntax:

formatDateTime(dateTime, format)

Example:

Expression: formatDateTime('2023-10-13T10:00:00Z', 'yyyy-MM-dd')

Output:

Output: '2023-10-13'

Example: indexOf() – Finding the Index of a Substring

The indexOf() function is used to find the position of a specified substring within a given string. It takes the original string and the substring to search for as parameters and returns the index (position) of the first occurrence of the substring within the string.

Syntax:

indexOf(originalString, substring)

Example:

Expression: indexOf('Hello, World!', ',')

Output:

Output: 5

Read Also: IndexOf Function in Power Automate: 10 Real-time Examples with SharePoint Online

Example: rand() – Generating a Random Number

The rand() function is used to generate a random number between 0 and 1. It does not require any parameters and returns a random decimal number.

Syntax:

rand()

Example:

Expression: rand()

Output:

Output: A random number

Example: randBetween() – Generating a Random Integer in a Range

The randBetween() function is used to generate a random integer within a specified range. It takes two parameters: the minimum and maximum values of the desired range (inclusive), and returns a random integer within that range.

Syntax:

randBetween(minValue, maxValue)

Example:

Expression: randBetween(1, 10)

Output:

Output: A random integer between 1 and 10 (inclusive)

Example: trim() – Trimming Whitespace

The trim() function is used to remove leading and trailing whitespace from a given string. It takes a string as a parameter and returns a new string with the leading and trailing whitespace removed.

Syntax:

trim(string)

Example:

Expression: trim(' Trim me! ')

Output:

Output: 'Trim me!'

Example: toUpperCase() – Converting to Uppercase

The toUpperCase() function is used to convert all characters in a string to uppercase. It takes a string as a parameter and returns a new string with all characters in uppercase.

Syntax:

toUpperCase(string)

Example:

Expression: toUpperCase('power automate')

Output:

Output: 'POWER AUTOMATE'

Example: toLower() – Converting to Lowercase

The toLower() function is used to convert all characters in a string to lowercase. It takes a string as a parameter and returns a new string with all characters in lowercase.

Syntax:

toLower(string)

Example:

Expression: toLower('Power Automate')

Output:

Output: 'power automate'

Example: chunk() – Chunking an Array

The chunk() function is used to divide an array into smaller, equally sized chunks. It takes two parameters: the array and the chunk size, and returns an array of chunks.

Syntax:

chunk(array, chunkSize)

Example 1:

Expression: chunk('abcdefghijklmnopqrstuvwxyz', 10)

Output:

Output: ['abcdefghij', 'klmnopqrst', 'uvwxyz']

Example 2:

Expression: chunk(createArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 5)

Output:

Output: [ [1,2,3,4,5], [6,7,8,9,10], [11,12] ]

Example: endsWith() – Checking if a String Ends With a Suffix

The endsWith() function is used to determine whether a given string ends with a specified suffix.

Syntax:

endsWith(string, suffix)

Parameters:

  • string (string): The input string that you want to check.
  • suffix (string): The substring that you want to check for at the end of the input string.

Example:

Expression: endsWith('Hello, World!', 'World!')

Output:

Output: true

Example: formatNumber() – Formatting a Number

The formatNumber() function is used to format a numerical value as a string with specified formatting options, such as the number of decimal places and thousand separators.

Syntax:

formatNumber(<number>, <format>, <locale>?)

Parameters:

  • number (number): The numerical value to be formatted.
  • format: A composite format string that specifies the format that you want to use..
  • locale: The locale to use as supported by “number.ToString(<format>, <locale>)”. If unspecified, the value is en-us. If locale isn’t a valid value, an error is generated.

Example:

Expression: formatNumber(1234567890, '0,0.00', 'en-us')

Output:

Output: 1,234,567,890.00

Example: guid() – Generating a Globally Unique Identifier (GUID)

The guid() function is used to generate a globally unique identifier (GUID), also known as a UUID (Universally Unique Identifier). A GUID is a 128-bit value often used to uniquely identify resources.

Syntax:

guid()

Parameters:

This function does not require any parameters.

Example:

Expression: guid()

Output:

Output: A generated GUID, e.g., 'eb14f204-0400-4b2c-9844-6e987d5ccf1b'

Note:

Example: slice() – Extracting a Portion of a String

The slice() function is used to extract a portion of a string based on the specified start and end positions.

Syntax:

slice(string, start, end)

Parameters:

  • string (string): The input string from which to extract a portion.
  • start (number): The starting index (inclusive) to begin extracting the substring (0-based index).
  • end (number, optional): The ending index (exclusive) to end the extraction. If not specified, it extracts until the end of the string.

Example:

Expression: slice('Power Automate is great!', 6, 14)

Output:

Output: 'Automate'

Example: Custom isFloat() Function – Checking if a Value is a Float

We’ll create a custom expression that checks if a given value is a floating-point number. It returns a boolean indicating whether a string is a floating-point number.

Syntax:

isFloat('<string>', '<locale>'?)

Parameters:

  • <value>:  The string to examine, this is a required parameter.
  • <locale>:  The RFC 4646 locale code to use, this is an optional parameter.

Example:

Expression: isFloat('10,000.00')

Output:

true

Example: lastIndexOf() – Finding the Last Occurrence of a Substring

The lastIndexOf() function is used to find the position of the last occurrence of a specified substring within a given string. It takes the original string and the substring to search for as parameters and returns the index (position) of the last occurrence of the substring within the string.

Syntax:

lastIndexOf(originalString, substring)

Parameters:

  • originalString (string): The original string in which to search for the substring.
  • substring (string): The substring to search for within the original string.

Example:

Expression: lastIndexOf('Hello, World! Hello, Universe!', 'Hello')

Output:

Output: 14

Read AlsoLastIndexOf Function in Power Automate With 10 Real-Time Examples

Example: nthIndexOf() Function – Finding the nth Occurrence of a Substring

The nthIndexOf() function helps in finding the position of the nth occurrence of a specified value within a string or an array. Its syntax is straightforward and efficient.

Syntax:

nthIndexOf('<text>', '<searchText>', <occurrence>)

Parameters:

  • <text>:  The string that contains the substring to find.
  • <searchText>:  The substring to find.
  • <occurrence>:  A number that specifies the nth occurrence of the substring to find. If occurrence is negative, start searching from the end.

Example:

Expression: nthIndexOf('123456789123465789', '12', 2)

Output:

9

Read AlsonthIndexOf Function in Power Automate: 10 Real-time Examples

Example: startsWith() – Checking if a String Starts With a Prefix

The startsWith() function is used to determine whether a given string starts with a specified prefix and returns a Boolean output.

Syntax:

startsWith(string, prefix)

Parameters:

  • string (string): The input string that you want to check.
  • prefix (string): The substring that you want to check for at the beginning of the input string.

Example:

Expression: startsWith('Hello, World!', 'Hello')

Output:

Output: true

Example: isInt() Function – Checking if a Value is an Integer

The isInt() function is used to check if a given value is an integer and it returns a boolean that indicates whether a string is an integer.

Syntax: 

isInt('<string>')

Example:

Expression: isInt('10')

Output:

true

Example: substring() – Extracting a Substring

The substring() function is used to extract a substring from a given string based on the specified start index and length.

Syntax:

 substring(string, startIndex, length)

Parameters:

  • string (string): The input string from which to extract a substring.
  • startIndex (number): The starting index (inclusive) from which to begin extracting the substring (0-based index).
  • length (number): The length of the substring to extract.

Example:

Expression: substring('Hello, World!', 7, 5)

Output:

Output: 'World'

Notes:

  • The above function, as explained above, we can use while working with dynamic data from SharePoint Online List or Document Library, or any other data sources.
  • The string used in these functions is case-insensitive; it doesn’t matter if it’s lower or uppercase. For example, “I like to work with Power Automate’ is the same as “I like to work with Power Automate’.

Summary: String Functions in Power Automate (List of Functions in Power Automate)

Thus, in this article, we have learned about how to work with various string functions in Power Automate, such as add(), concat(), length(), replace(), split(), formatDateTime(), indexOf(), rand(), randBetween(), trim(), toUpperCase(), toLower(), chunk(), endsWith(), formatNumber(), guid(), slice(), isFloat(), lastIndexOf(), nthIndexOf(), etc.

This article explores a range of essential string manipulation functions available in Power Automate, showcasing their usage through practical examples. From concatenation to substring extraction, these functions play a crucial role in automating flows effectively. By illustrating their syntax and demonstrating their application in real-life scenarios, this article provides a comprehensive guide for users to harness the power of string functions within Power Automate. Readers can grasp the versatility and usefulness of these functions in enhancing their automation tasks, enabling streamlined data processing and management within their Power Automate flows.

See Also: Power Platform Articles

You may also visit the Power Platform article hub, where you will see a bunch of articles focusing on Power Platform, like Power Automate, Power Apps, etc. All the articles are written with real-time project scenarios and troubleshooting techniques.

About Post Author

Do you have a better solution or question on this topic? Please leave a comment