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

View solution in original post

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,003)