Problem Statement
There is no direct function in ADF / Fabric Data Pipeline to get the Index position of a character in a string.
Is it possible to get the Index Position of the Nth Occurrence of a Character in String in Azure Data Factory / Fabric Data Pipeline?
Prerequisites
- Azure Data Factory / Synapse Pipeline / Fabric Data Pipeline.
Solution

The first step would be to split the input String into an Array of characters.
- The initial 2 activities in the above flow: Set variable & For each are for #1.
- The blog Split a String into an Array of Characters with No Delimiter in Azure Data Factory provides the details for the same.
- Next, we would need to iterate over the String Array length for each character comparison.

- Check whether the current iteration character is equivalent to the Search character.
@equals(variables('StringArray')[item()], pipeline().parameters.SearchCharacter) - If the character matches then follow the below flow, else skip.

- Have a counter to count the occurrence of that character within the string.

- In ADF, a variable cannot be self-referenced within the Set variable activity; hence we need an intermediate variable.

- Start capturing the index position of the Character occurrence.

- Set the Temp Index position if the Count of the occurrence matches within the Nth Occurrence parameter.
@if( equals(variables('Count'), pipeline().parameters.OccurenceCount), string(item()), variables('FinalPositionIndex') ) - Assign the Final value for the output via Set Variable activity.








Join the conversation! Your thoughts help the community grow.