Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Process Mining
Answered

Replace a specific string in a text variable

(0) ShareShare
ReportReport
Posted on by

I want to replace a text according to its position since it can be repeated


Example text that I want to modify:

Task: "x"; Answer: "Pending",
Task: "z"; Answer: "Pending",
Task: "x"; Answer: "Pending"


As you can see in the text, it is repeated Task: "x"; Answer: "Pending"

then when using the replace:

Replace (Text to modify, "Task:" x "; Response:" Pending "", Task: "x"; Response: "Approved")

then the result will be:


Task: "x"; Answer: "Approved",
Task: "z"; Answer: "Pending",
Task: "x"; Answer: "Approved"

I just need to update the last one, how do I do this?

Categories:
  • Community Power Platform Member Profile Picture
    on at
    Re: Replace a specific string in a text variable

    thank you very much it worked well 😃

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Replace a specific string in a text variable

    Hi

     

    If you copy the below to your clipboard and paste into a new flow, I have prepared a scope with a demo:

     

    HowToCopyPasteSolution.gif

     

    {"id":"0393a638-eb55-40dc-91d5-ce4d-2e262986","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"DamoBird365_rename_last_occurrence","operationDefinition":{"type":"Scope","actions":{"String":{"type":"Compose","inputs":"Task: \"x\"; Answer: \"Pending\",\nTask: \"z\"; Answer: \"Pending\",\nTask: \"x\"; Answer: \"Pending\"","runAfter":{}},"LastPosition":{"type":"Compose","inputs":"@lastIndexOf(outputs('String'),'Task: \"x\"; ')","runAfter":{"String":["Succeeded"]}},"LastPositionString":{"type":"Compose","inputs":"@substring(outputs('String'),outputs('LastPosition'))","runAfter":{"LastPosition":["Succeeded"]}},"Replace":{"type":"Compose","inputs":"@replace(outputs('LastPositionString'),'Task: \"x\"; Answer: \"Pending\"', 'Task: \"x\"; Answer: \"Approved\"')","runAfter":{"LastPositionString":["Succeeded"]}},"StartOfString":{"type":"Compose","inputs":"@substring(outputs('String'),0,outputs('LastPosition'))","runAfter":{"Replace":["Succeeded"]}},"Concat":{"type":"Compose","inputs":"@concat(outputs('StartOfString'),outputs('Replace'))","runAfter":{"StartOfString":["Succeeded"]}}},"runAfter":{}}}

     

    Using LastIndexOf, you can get the last occurence of the string you want to replace, replace the value on the substring and then concat the original start of the string with the substring that you have replaced.  I have overexagerated the solution by including all steps but this could be simplified to reduce the number of actions.

     

    DamoBird365_0-1620128265727.png

    DamoBird365_1-1620128275637.png

     

     

    Input is 

    DamoBird365_2-1620128291153.png

     

    Output is

    DamoBird365_3-1620128323688.png

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Automate - Process Mining

Overall leaderboard