web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Replace a specific str...
Power Automate
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:
I have the same question (0)
  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    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 😉

  • Community Power Platform Member Profile Picture
    on at

    thank you very much it worked well 😃

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard