cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
King
Advocate III
Advocate III

Replace a specific string in a text variable

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?

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Super User
Super User

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 😉

View solution in original post

2 REPLIES 2
DamoBird365
Super User
Super User

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 😉

thank you very much it worked well 😃

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,231)