cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ctarascio
Helper I
Helper I

Remove comma after last value in string

Hi,

I am retrieving the values from a SharePoint multiple choice item. To do that I am doing this: 

  • Initializing a string variable called "TypeofChangeChoices"
  • Using the "Append to stringvariable" action to append all of the selections to the "TypeofChangeChoices" variable defined above. I am using this in the value field: TypeofChange value followed by a comma 

This is working fine in that I am getting all the values but the flow is adding a comma at the end of the string, when there are no more values: e.g. Work Schedule, Compensation,
I'd like to omit the last comma: if there are no more values omit the comma

 

Is there a way to do this?

 

Thanks for any help.

Cynthia

 

10 REPLIES 10
Pstork1
Dual Super User
Dual Super User

use the following function on the string

substring(stringvariable,1,add(length(stringvariable),-1))


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi, Thanks so much for responding. 

I can't figure out where to add the substring function. I've attached a screen shot of the 2 actions involved. 

here are the 2 actions involved:

ctarascio_0-1603911184312.png

can you tell me where to put the substring function? I am obviously very new to all this but i did try to figure it out. The substring function does not appear anywhere in my expression list. 

 

Thanks again,

cynthia

 

 

 

Hello again, I did figure out (I think) where to put the substring function but the last cooma is still there. 

  1. I added another initialize variable after the "append to each" in the screen shot below and that is where i inserted the function. But the comma is not getting removed.

I must be doing something wrong. Do you have any suggestions?

 

Thanks,

Cynthia

 

There is a way to do what you want, which is basically remove the last character of a string with an expression like this:

 

substring(variables('TypeofChangeChoices'), 0, 
	sub(length(variables('TypeofChangeChoices')), 1)
	)

 

 

If I may, I would suggest a different approach for future flows. Instead of appending to a string variable, instead use an array variable. Then if you need to use that array variable as a delimited string, you can use the join expression to give you the string representation with whatever delimiter you choose.

 

This expression can go into a compose action, like this:

substring.PNG

You can then use this compose action as the dynamic content for any subsequent actions.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

You'll need to add a Compose after you exit the Apply to each loop and add the substring code there.  Use the variable as the text.  Then the text without the trailing comma will be the output of the compose.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

hi,

sorry to be so dense.

i added the compose action after the apply to each action but the only option i have is to enter "*Inputs". 

Is that where you want me to enter the substring function, replacing "stringvariable" with "TypeofChangeChoices"? 

 I will keep trying...

 

thanks,

cynthia

 

 

When the inputs field comes up you should have access to the dynamic content dialog.  You enter the formula in the expressions tab in that dialog.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

I finally got this to work using this solution:

ctarascio_0-1603998440021.png

i used 2 compose actions. The second one contains this substring expression:

substring(outputs('Compose-TypeofChange-xtracomma'),0,sub(length(outputs('Compose-TypeofChange-xtracomma')),1))

 

This worked perfectly. I can't take credit for this though as I found the solution in this post:

https://powerusers.microsoft.com/t5/General-Power-Automate/Removing-the-last-character-in-the-string...

 

Thanks for trying to help me. I really appreciate it.

Cynthia

 

honey123
New Member

Hello can i ask what did u put in the first compose? Thanks! experiencing the same problem

ctarascio
Helper I
Helper I

ctarascio_0-1644332260607.pngctarascio_1-1644332309071.pngctarascio_2-1644332342757.png

This is what the substring code is:

substring(outputs('Compose-TypeofChange-xtracomma'),0,sub(length(outputs('Compose-TypeofChange-xtracomma')),1))

 

Please let me know if this helped you to resolve your issue.

thanks,

cynthia

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 (2,479)