truncating the sentence upto certain characters

hi team,
I have a paragraph and it has around 301 characters. Now, i wanted to truncate to 70 characters is there any possibility to do it.

Example: SPHERICAL,SELF-ALIGNING,TAPERED,STEEL,22226 CCK/W33,REFERENCE:2600 RPM,LIMITING:3600 RPM,ANNULAR GROOVE&(3) LUBRICATION HOLE,CENTRE DISTANCE BETWEEN BOLT HOLES:159-161 MM,TOP WIDTH:32 MM,115D1,REFLECTIVE,ANTISCALANT SEA WATER,HYPERSPERSE,REFERENCE:20000 RPM,LIMITING:13000 RPM,SEALED LIMITING:6300 RPM

By the Above example, i wanted to truncate to 70 characters like below output
1.SPHERICAL,SELF-ALIGNING,TAPERED,STEEL,22226 CCK/W33,REFERENCE:2600 RPM
2.LIMITING:3600 RPM,ANNULAR GROOVE&(3) LUBRICATION HOLE,CENTRE DISTANCE
3. BETWEEN BOLT HOLES:159-161 MM,TOP WIDTH:32 MM,115D1,REFLECTIVE,ANTISCA
4. LANT SEA WATER,HYPERSPERSE,REFERENCE:20000 RPM,LIMITING:13000 RPM,SEAL

Note: Sl no are not required in the output just for reference in have made

Hi @Ranjit , this is not truncating. Truncating up to 70 characters means to remove/delete everything after 70 characters. What you are looking for is text wrapping.

FYI, your result is not exactly accurate. If you look at the original text “W33,REFERENCE:2600 RPM,LIMITING:3600”, there is a comma between “RPM” and “LIMITING”, so your line #2 should start with that comma, therefore shifting everything by 1. You are also missing a 5th line.

I’m not sure if there is a feature for this, at least none that I know of. If there is no feature for this, it is probably best done via a Recursive Loop.

I put something together that looks like this:
image

Results:
image

You can parameterize where you want to wrap the text via the Variable Creator node:
image

Here’s the workflow:
wrapping text to multiple rows.knwf (16.8 KB)

1 Like

Hi @Ranjit & @bruno29a

@bruno29a thanks for posting a solution for this challenging problem. I didn’t realize it was about wrapping text into multiple rows but going through your so nice explanation made me to notice it is the case.

Complementary to your solution @bruno29a, I remember I posted a while ago a solution for a very similar problem. Maybe it could help with little adaptation too :wink:

I’m truncating up to 1000 characters but you can adapt it to whatever the size. The interest of this approach is that it preserves the words without cutting them in half.

Hope it helps too.

Best

Ael

Thanks for sharing @aworker . Based on @Ranjit 's screenshot, it looks like the intention is to cut the string without preserving the words (“ANTISCALANT” being splitted between lines 3 and 4, “SEALED” being splitted between lines 4 and 5). That is why I took this approach.

Indeed @bruno29a. I’m just suggesting an alternative solution in case it may help too :wink:

Best

Ael

1 Like