cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AmyCroker
Frequent Visitor

Split string if longer than x number of characters into new row/new file

Hi Community!

 

Looking for some help, I have created a flow which takes a CSV file- removes nulls, unwanted columns and transposes the column I want into a row and saves as a txt file. The purpose of this is for users to easily be able to copy and paste specific information into our system from an email attachment.

 

So from this:

 

Column1, Column 2, Column 3

A              B                C

A              B                C

A              B                C

 

to this:

 

B,B,B

 

I'm wondering if there is a way to split the string after a certain number of characters e.g. 20 and either create a new row on the CSV or creates a new TXT file with the data.

 

Screenshot of how the data starts and ends up:

EG1.PNG

 

EG2.PNG

 

Best Wishes

 

Amy

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AmyCroker 

 

My clever mate @Paulie78 came up with the following:

DamoBird365_0-1629396123569.png

 

Where from is:

range(0, add(div(length(outputs('Compose')), 10), 1))
and Map is:
substring(outputs('Compose'), mul(item(), 10), if(greater(add(mul(item(), 10), 10), length(outputs('Compose'))), sub(length(outputs('Compose')), mul(item(), 10)), 10))
 
Substring is based on starting position and length.  

The clever bit is the IF statement to cater for the last substring.

 

Oh, and I nearly forgot, you can then join() the array with a return line or however you please.

 

Damien

View solution in original post

4 REPLIES 4
DamoBird365
Super User
Super User

Hi @AmyCroker 

 

You can check the length of a string with length() and potentially split with substring().  

 

Are you trying to shorten the output from FinalString compose action? What is the desired output?

 

Damien

AmyCroker
Frequent Visitor

@DamoBird365  thanks for the advice!

 

The desired output would be if the output in the FinalString compose action is longer than 255 characters it would split the string either onto a new row or a new txt file without cutting off a value.

 

So just for ease an example if i wanted to split it if longer than 10 characters it would look like this:

 

final string compose output: 1234,2345,3456,4567,5678

 

Would go to (either new rows or new txt files):

1234,2345,

3456,4567,

5678

 

Many thanks for your help

 

Amy

Hi @AmyCroker 

 

My clever mate @Paulie78 came up with the following:

DamoBird365_0-1629396123569.png

 

Where from is:

range(0, add(div(length(outputs('Compose')), 10), 1))
and Map is:
substring(outputs('Compose'), mul(item(), 10), if(greater(add(mul(item(), 10), 10), length(outputs('Compose'))), sub(length(outputs('Compose')), mul(item(), 10)), 10))
 
Substring is based on starting position and length.  

The clever bit is the IF statement to cater for the last substring.

 

Oh, and I nearly forgot, you can then join() the array with a return line or however you please.

 

Damien

AmyCroker
Frequent Visitor

@DamoBird365 and @Paulie78  words can't describe my feelings towards you both right now! Thank you so much, I've been looking at split and substring for almost a solid week trying to figure it out. Thank you so much!!!

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (4,905)