Forum Discussion

NothingHeavy's avatar
NothingHeavy
Copper Contributor
Jul 28, 2025
Solved

Inserting delimiter every nth space in a string

Scope: Building a spreadsheet that takes Fault Tree analysis inputs in a table and then outputs everything in DOT language to visualize the information using Graphviz.

User will input an Event ID, Event Description, and Supporting Evidence. The Parent ID is automatically generated.

The event descriptions are strings of varying length and there is no text wrapping capability native to Graphviz. I am currently inserting "\n" after the 2nd and 4th delimiters with nested substitute functions. Nesting will only work if I know the strings will all be less than a certain length or have a certain number of spaces.

The plan is to use a formula to insert the "\n" delimiter after every nth word. N would be set to 3 in the example below.

 

  • I recommend adding this LAMBDA function to your Name Manager:

    =LAMBDA(inTxt,wordCount, TEXTJOIN(" ",1,DROP(TOCOL(EXPAND(WRAPROWS(TEXTSPLIT(inTxt," "),wordCount,""),,wordCount+1,"\n")),-1)))

    Then you can just call it using:

    =NewLine(A1,3)

    where A1 is the text and 3 is how many words to space it by

    line 13 inserts every 3rd word and line 14 inserts every 4th word

1 Reply

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    I recommend adding this LAMBDA function to your Name Manager:

    =LAMBDA(inTxt,wordCount, TEXTJOIN(" ",1,DROP(TOCOL(EXPAND(WRAPROWS(TEXTSPLIT(inTxt," "),wordCount,""),,wordCount+1,"\n")),-1)))

    Then you can just call it using:

    =NewLine(A1,3)

    where A1 is the text and 3 is how many words to space it by

    line 13 inserts every 3rd word and line 14 inserts every 4th word

Resources