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?
thank you very much it worked well 😃
Hi
If you copy the below to your clipboard and paste into a new flow, I have prepared a scope with a demo:
{"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.
Input is
Output is
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 😉