web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Splitting text string into substrings of a maximum character length

(0) ShareShare
ReportReport
Posted on by 9

I need to take the contents of a field that has a large maximum length, and break the string into substrings of maximum length 60 characters.  I need to split the string on spaces, so that no words are split.  I then will need to patch each <=60 ch substring as a field in a new record to another table.  Each substring will have its own record.  I am having a lot of trouble with splitting the initial string in this way,  so any help would be greatly appreciated thank you!

I have the same question (0)
  • takolota1 Profile Picture
    4,944 Moderator on at
    Re: Splitting text string into substrings of a maximum character length

    @nw_maryland 

    You should use the Chunk( ) expression. It will automatically split a string into an array of items of a set length

    https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#chunk

  • nw_maryland Profile Picture
    9 on at
    Re: Splitting text string into substrings of a maximum character length

    Thank you - is there a way to specify using Chunk() that the string should only be split on a space?  The trouble I have been having is that I have a set maximum length (60 characters) and am needing to separate substrings on the space that falls closest to the maximum length of each substring.  

  • takolota1 Profile Picture
    4,944 Moderator on at
    Re: Splitting text string into substrings of a maximum character length

    So that is more complicated…

     

    You can create something that will output 60 characters +the characters up to the next space

     

    Create a Compose action with the Chunk( ) on the string

     

    Create a Select action

    In the From input use something like

    Range(0, length(outputs('Compose')))

     

    Then in the Map input use something like 

    concat(join(skip(split(outputs('Compose')[item()], ' '),1), ' '), first(split(outputs('Compose')[add(1,item())], ' ')))
  • AlexEncodian Profile Picture
    4,409 Moderator on at
    Re: Splitting text string into substrings of a maximum character length

    I think the ask is for 60 or less characters.

    Something like this could work (check syntax) and then use a do until condition to repeat the step:

     

    replace(first(chunk('string', 60)),last(split(first(chunk('string', 60))," ")),"")


    Explanation:


    split original string into arrays of 60 characters using chunk()

     

    chunk('string', 60)


    take first 60 character element

     

    first(chunk('string', 60))


    split this by space " " character

     

    split(first(chunk('string', 60))," ")


    The last element of the split output array are the characters after the last " " that need to be removed. To get these characters: 

    last(split(first(chunk('string', 60))," "))


    Remove these characters from the first 60 characters using replace()

    replace(first(chunk('string', 60)),last(split(first(chunk('string', 60))," ")),"")


    That's your first result string (there might be an extra space at the end that you can optionally deal with).

    Remove this first result from the original string using replace() and then start the process again on that result until you have less than 60 characters left.

  • Verified answer
    grantjenkins Profile Picture
    11,059 Moderator on at
    Re: Splitting text string into substrings of a maximum character length

    I had someone ask that a few days ago. See my response which works on commas - so you would just need to change the following from comma to space, and the rest of the flow should work for you.

     

    //Change
    lastIndexOf(slice(outputs('Compose'), 0, add(variables('index'), variables('chunk'))), ',')
    
    //To
    lastIndexOf(slice(outputs('Compose'), 0, add(variables('index'), variables('chunk'))), ' ')

     

    https://powerusers.microsoft.com/t5/Building-Flows/Break-a-string-into-chunks/m-p/2432090/highlight/true#M271582

  • nw_maryland Profile Picture
    9 on at
    Re: Splitting text string into substrings of a maximum character length

    Thank you so much this was perfect.  I was able to adapt this to our needs, and we were able to add to the flow you linked to also break under additional conditions.  So helpful thanks so much!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 722 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 461 Moderator

#3
developerAJ Profile Picture

developerAJ 283

Last 30 days Overall leaderboard