cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cchicken
New Member

How to remove the last element of an array?

How would a compose an output to remove the last element of an array? My specific use case would be to remove an extension from a file name..

 

For example, I have a file name called: this.is.a.test.txt

Desired output: this.is.a.test

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
DeepakS
Resident Rockstar
Resident Rockstar

Hi @cchicken 

 

As @Julien2  suggested you should use substring function achieve this, I would prefer to add on the solution is to get the length of the last element dynamically:

MyString is variable storing : this.is.a.test.txt (You can actually use any other string )

 

 
substring(variables('MyString'),0,lastIndexOf(variables('MyString'),'.'))
 
-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

4 REPLIES 4
Julien2
Super User
Super User

Hi @cchicken ,

 

This expression might help you:

substring(outputs('Compose'),0,sub(length(outputs('Compose')),4))

I hope it helps!

Regards,

Julien 

@Julien2 

 

I think this works. Can you briefly explain how this works? 

 

Thank you!

Hi @cchicken ,

 

The substring function allows extracting part of a string. I have specified where to start at position 0 and how many characters I want.
To find how many characters to take, I have used the length expression to give me the string length for the result.

 

If I have answered your question, please mark your post as Solved.

Thank you.

DeepakS
Resident Rockstar
Resident Rockstar

Hi @cchicken 

 

As @Julien2  suggested you should use substring function achieve this, I would prefer to add on the solution is to get the length of the last element dynamically:

MyString is variable storing : this.is.a.test.txt (You can actually use any other string )

 

 
substring(variables('MyString'),0,lastIndexOf(variables('MyString'),'.'))
 
-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (4,821)