DEV Community

Cover image for Spellbinding String Manipulation: Wizardry with Power Automate
Bala Madhusoodhanan
Bala Madhusoodhanan

Posted on

Spellbinding String Manipulation: Wizardry with Power Automate

Intro:

Lets unravel the secrets of Power Automate and its mystical abilities in handling strings. Just like ancient scrolls filled with arcane symbols, strings hold immense power – they carry information, convey messages, and shape our digital world. we’ll explore various string manipulation techniques, from simple incantations like text searching to more complex spells like splitting strings into fragments. Whether you’re a seasoned mage or a novice spellcaster, there’s something here for everyone.

Data Setup:
Leveraged compose varaible to store the string / paragraph

Image description

Lets unravel the secrets of Power Automate and its mystical abilities in handling strings. Just like ancient scrolls filled with arcane symbols, strings hold immense power – they carry information, convey messages, and shape our digital world. we’ll explore various string manipulation techniques, from simple incantations like text searching to more complex spells like splitting strings into fragments. Whether you’re a seasoned mage or a novice spellcaster, there’s something here for everyone.

Tip 1: Upper Case
Convert a text string to uppercase

toUpper(outputs('String_Input'))
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 2: Lower Case
Convert a text string to lowercase

toLower(outputs('ToUpper'))
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 3: Concat

Join multiple text strings into a single text string.

This example I have appended INTRO and CLRF to the text

concat('INTRO:',decodeUriComponent('%0A'),outputs('String_Input'))
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 4: IndexOf Function
Find the starting position of a substring in a text string

Searching for the text ancient

indexOf(outputs('String_Input'),'ancient')
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 5: Search Text
Another cool way to search for starting position of the string is using search text function

{
    "kind": "indexOf",
    "inputs": {
        "text": "@outputs('String_Input')",
        "searchText": "ancient"
    }
}
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Image description

Tip 6: LastIndexOf Function
Find the last position of a substring in a text string

lastIndexOf(outputs('String_Input'),'strings')
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 7: Length Function
Returns the number of characters in a text string

length(outputs('String_Input'))
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 8: NthIndexOf Function

Find the nth position of a substring in a text string

nthIndexOf(outputs('String_Input'),'like',2)
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 9: Replace Function

Replace a substring of old text with another substring of new text.

replace(outputs('String_Input'),'ancient','antique')
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 10: Slice Function
Extract a range of characters from the middle of a text string

slice(outputs('String_Input'),101,108)
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 11: Split Function
Split a text string into an array of values by specifying a delimiter

split(outputs('String_Input'),'.')
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 12: Substring Function
Extracts a substring given number of characters from the middle of a supplied text string

substring(outputs('String_Input'),101,7)
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Tip 13: Trim Function
Removes blank spaces from the start and the end of a text string

trim(outputs('String_Input'))
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

Wield the magic of Power Automate
As you wield your digital wand, remember that each function is a spell waiting to be cast. The CONCAT spell weaves disparate strings into a harmonious melody, while the ENDSWITH charm discerns truth from illusion at the tale’s end

Illusions Demystified:

  • Slice:
  1. If startIndex is greater than the string length, it returns an empty string.

  2. If endIndex isn’t specified or greater than the string length, it takes up to the end of the string.

  3. If startIndex or endIndex is negative, it calculates the index value as the sum of the string length and the Index and then calculates accordingly. Bet you did not know that.

slice(outputs('String_Input'),-100)
🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน 🔴 Hot News: balagmadhu/spellbinding string manipulation wizardry with power automate p - ประเด็นร้อน

Image description

The text position for "gments. Whether" is 397

Image description

The length is 497 and hence the Slice -100 would start from ( -100+397)

Top comments (0)