cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
tianaranjo Continued Contributor
Continued Contributor

Split string

Greetings,

 

I have a need to split the following string from this:

1234_5678.901.A_1.jpg

to this:

1234_5678.901.A

If I use the following split function, it splits at the first '_', where I need it to split at the 2nd '_'

split(outputs('Get_File_Name'), '_')[0]

Is there a way to reference the second underscore in the split function?

Thank you; in advance!

 

Update - I resolved this by removing the second '_' in the generated filename and replacing it with a '-'.  I then used the following split function:

split(outputs('Get_File_Name'), '-')[0]

This works for my needs.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Split string

Hi @tianaranjo,

 

You could also take a try with expression to achieve your needs and don't need to replace '_' with '-':

split(outputs('Get_File_Name'), '_1.')[0]

 

Best regards,

Alice

View solution in original post

6 REPLIES 6
Community Support
Community Support

Re: Split string

Hi @tianaranjo,

 

You could also take a try with expression to achieve your needs and don't need to replace '_' with '-':

split(outputs('Get_File_Name'), '_1.')[0]

 

Best regards,

Alice

View solution in original post

Administrator
Administrator

Re: Split string

Hello,  @tianaranjo!

Have you had an opportunity to apply @v-yuazh-msft‘s recommendation to adapt your Flow? If yes, and you find that solution to be satisfactory, please go ahead and click “Accept as Solution” so that this thread will be marked for other users to easily identify!


Thank you for being an active member of the Flow Community!

-Gabriel
Flow Community Manager

-Gabriel
Microsoft Power Automate Community Manager
Are YOU a member of your local Power Automate User Group?
Fill out This Form to claim your Community User Group Member Badge!
StephenM Advocate I
Advocate I

Re: Split string

i dont quite understand what the [0] does on the expression - could someone please explain

 

split(outputs('Get_File_Name'), '_1.')[0]

 thanks

Stephen

StephenM Advocate I
Advocate I

Re: Split string

Also, how did youremove the second '_' in the generated filename and replace it with a '-' ? could you explain that please

 

many thanks

Stephen

tianaranjo Continued Contributor
Continued Contributor

Re: Split string

@StephenM I'm not an expert so bear with me and if I get this incorrect, hopefully the others on this chain will correct me.  The '0' is referring to an index or location in the string.  Hopefully these links will help:

https://www.w3schools.com/jsref/jsref_split.asp

Optional. An integer that specifies the number of splits, items after the split limit will not be included in the array

 

https://www.digitalocean.com/community/tutorials/how-to-index-split-and-manipulate-strings-in-javasc...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

 

 

 

tianaranjo Continued Contributor
Continued Contributor

Re: Split string

@StephenM - within PowerApps, I was using Concatenate to join the fields with  the '_'.  I simply changed that to '-'.

Helpful resources

Announcements
Did you attend MBAS? Claim your badge

Attending MBAS? Claim your badge

Whether you’ve streamed the digital event live, or you're watching on-demand, claim your attendee badge to sport on your profile.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (5,950)