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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Replace last comma wit...
Power Automate
Answered

Replace last comma with an &&

(0) ShareShare
ReportReport
Posted on by 34

Hi all,

 

I would really appreciate some help as I can't seem to figure this one out. I know how to replace characters, but what I am struggling with is how to replace the last comma in a string with an ' & '. 

 

My text example is -  Bob Smith, Julie White, Andrew Blaa, Lucy Luu

I would like the output to be - Bob Smith, Julie White, Andrew Blaa & Lucy Luu

I have used lastindexof to detetermine the position of the last comma e.g. lastIndexOf(outputs('TEXT'),',')

The question is now how do I replace it. The replace function expects a string and not an integer. I tried to use substring to give me the string value which resulted in a ',' which is correct, although it would then look to replace all commas. I only want to replace the last comma with an &

Any help would be greatly appreciated. 

Categories:
  • Verified answer
    Gowmadrid82 Profile Picture
    34 on at

    I did an hour or two of googling last night and looking at this forum to try and work it out, but I have now managed to find the answer. For those struggling with the same issue, this was the solution. 'removelastcomma' is the dynamic reference to the output that contains my names

    concat(substring(outputs('removelastcomma'),0,lastIndexOf(outputs('removelastcomma'),',')), ' and ',slice(outputs('removelastcomma'),add(lastIndexOf(outputs('removelastcomma'),','),1)))
  • Verified answer
    v-wenjuan-msft Profile Picture
    Microsoft Employee on at

    Hi @Gowmadrid82 ,

     

    Please try this function:

     

    concat(take(outputs('Compose'),sub(outputs('Compose_2'),1)),'&',slice(outputs('Compose'),add(outputs('Compose_2'),1)))

     

     

    vwenjuanmsft_0-1682414418148.png

     

    Here is the result:

    vwenjuanmsft_1-1682414458530.png

     

    Community Support Team _ Wenjuan Zou

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

     

  • Gowmadrid82 Profile Picture
    34 on at

    Thank you. I found the solution and put it in my last post, but this is a great alternative to use 'take'. Thank you, really appreciate your help

  • victorlee1 Profile Picture
    45 on at

    It fails if you have only one name on the list....

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 349 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard