Split String with a maximum of 40 characters and end with full words/characters

Hey i´ve got a problem with my workflow logic.

I have multiple Strings with different lengths and need to split it up with a maximum of 40 characters and no cuts inside a word.

Example:

TestString = “Ingredients: Salad mayonnaise (rapeseed oil, water, EGG YOLK, sugar, corn starch,
Brandy vinegar, spices, table salt, WHEAT STARCH, grape sugar,
Maltodextrins, thickeners: guar gum, locust bean gum,
Xanthan gum; Color: carotene; Flavor)”

Target:

FirstString =“Ingredients: Salad mayonnaise (rapeseed oil,”
SecString =“water, EGG YOLK, sugar, corn starch, Brandy”
3rdString ="vinegar, spices, table salt, WHEAT STARCH, "
and so on…

My actual workflow works with a SplitIndex Assign like this:

splitIndex = (TestString.ToString.Substring(0,40).LastIndexOf(" ")+1)

then a write line:
TestString.ToString.Substring(0,splitIndex)

this works but just for the first Target String

how can i continue this workflow till the end of the full String

Thank u!

Added an example workflow (Test String is in german so dont be suprised :slight_smile: )
Main.xaml (6.1 KB)

@thorem99
Welcome to the forum

we would suggest to make some requirements more sharp e.g.

  • do / do not break on / keep together in split with less then 40 () - Product Ingredients list inside ()
  • do / do not split related info XX% ABC not be split

Maybe you can tell us more about your case and what is to achive on higher process goal level

Okay let me try,

I get a list with some Articles and their Product Ingredients. The Product Ingredients are hold in one big String. The Bot have to bring these Product Ingredients in text fields in SAP where a maximum of 40 characters is capped. So i have to Split the one big String in smaller ones who have a maximum of 40 and dont cut in the middle of a word.

Sorry it´s my first time beeing active in the forum, if something isn´t clear let me know!

ok perfect

  • chunk has to be a maximum length of 40
  • must not (darf nicht) cut on words, but on related info like 5% Sugar can be cut on 5 and % Sugar

A very essential/ conservative approach would be to iterate over all chars from string within a fore each (item char from string) / do while and let it split if length is 40 or trace back when it is within middle of word.

Another approach is to use Regex:

And construct the split by adding the matches to a split as long the split will not exceed 40 chars

Is it possible to get a workflow for this example from u? I think i can follow your tipps but its hard for me right now to make the process work.

especially the fore each way doesn’t work for me when i just look at 1 item at the same time instead of the whole string…

regex is also completly new for me but i will try to get some knowledge about that now.

Thanks!

@thorem99


grafik

Find starter help here:
Regex_SplitParts_MaxCharLength_NoWordBreak.xaml (9.5 KB)

4 Likes

This is gold. Thank you very much! It works for me.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.