Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Split a text into 50-character long strings and a break line

msantoso
8 - Asteroid

Dear All,

 

I have description text that comes in a field. I need to split the text into lines. Each line cannot be more than 50 character long. And each line must finish with a breakline character. 

the difficulty is that a word cannot be broken, i.e if the 50th character is in the middle of a word, then the line should be broken before. 

and last but not least, the description should remain in one single field. 

I have attached an example. In column A the text comes with no beak lines. In column 2 there is a beakline after the word that is closest to the 50 character. 

I hope I am clear enough. 

thank you for you help

myriam

6 REPLIES 6
BenMoss
ACE Emeritus
ACE Emeritus

Hi @msantoso, this is an interesting problem!

 

I believe I have got a solution which I have attached.

 

Essentially I have parsed out each word into an indivdual line, then calculated the length of the word before doing a running total.

 

I have then used the floor function to acknowledge if each word should be on the 1st, 2nd, 3rd, etc. lines, before using the summerize tool to bring the strings back together.

 

newlines50chars.png

 

Ben

msantoso
8 - Asteroid

hi Ben, 

thanks a lot for your help. 

 

this is exactly doing what I needed. 

however, when I saved the output into a csv file, and opened it with Excel,  the text did not come into one single cell. 

Shouldn't we have a breakline after the last word of each subline? 

 

thank you

myriam

cmcclellan
13 - Pulsar

That also might be how Excel processes CSV files.  I'd recommend saving to XLS format and opening in Excel, or saving as CSV and opening in Notepad (or another text editor of your choice)

ponraj
13 - Pulsar

Here is my solution for your case.   Steps for formatting excel output as below.  Hope this is helpful. 

 

1.Open the excel output

2.Press Ctrl+A to select the output text. 

3.Click Home > Format > AutoFit Column Width

4.Click Home>Wrap Text to get the desired output. 

WorkflowWorkflowResultResultExcel outputExcel output

msantoso
8 - Asteroid

Hi Ponraj,

 

thank you so much for the solution!! 

One more thing I learned today

and one topic that I can close for today!

 

Have a nice day

Myriam

 

HansWolting
5 - Atom

Nice solution! Thanks for that.

One small fix I applied: I changed the calculation of Length to Lenght([F1])+1. This will take into account the spaces which are added when concatenating the words afterwards.

Labels