Spellbinding String Manipulation: Wizardry with Power Automate
Tags: powerplatform, powerautomate, powerfuldevs
Published: 2024-05-13 08:37:05

## 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.


**<u>Data Setup</u>**:
Leveraged compose varaible to store the string / paragraph 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxhtmdcls56cuh0qy8oq.png)


`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'))
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpzj6ewzrfcfqpfekuyu.png)



**Tip 2**: Lower Case
Convert a text string to lowercase

```
toLower(outputs('ToUpper'))
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1mbwy3ouv841wzss0fr.png)



**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'))
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tspcjj961qax9430r1wt.png)



**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')
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c3oxcpxkiq2qnid4h6u.png)



**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"
    }
}
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omm6lt2w4iq2k7ofz8xs.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19auc4bk2lfj0xp7vcb0.png)



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


```
lastIndexOf(outputs('String_Input'),'strings')
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29bp6zv4b9a5nbsdpohd.png)



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


```
length(outputs('String_Input'))
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2pg87sj35np4tv7ugn2.png)



**Tip 8**: NthIndexOf Function

Find the nth position of a substring in a text string


```
nthIndexOf(outputs('String_Input'),'like',2)
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/olvcyh85m1trdwpvis7p.png)



**Tip 9**: Replace Function

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

```
replace(outputs('String_Input'),'ancient','antique')
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qu0x1uplgd6avdalrxit.png)



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

```
slice(outputs('String_Input'),101,108)
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4am9ig8is6l2fetg0x5.png)



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


```
split(outputs('String_Input'),'.')
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9mpwxnnw14js8z7kvv7.png)



**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)
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uord3evhc8mmf42nfz1q.png)


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

```
trim(outputs('String_Input'))
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4d9oqk7o69874exhnbv.png)


**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)
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtwhmvnyqc8caz436x4m.png)

The text position for "gments. Whether" is 397

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7vsvk25s4dpjrh236gej.png)

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