Splitting text 1st X characters, 2nd X characters, 3rd, etc

Does anyone knows how I can split and save text from a multiline input like this;

_1st - 450 characters _

2nd - 450 characters

3rd - 450 characters

4rd - 450 characters

I tried it with “:truncated to & :truncated from end to” but I can’t figure out how to get text from the middle etc.

1 Like

You need to use a double version of those functions. So the first chunk was XXXXX:truncated to 450 characters. The second chunk would be initially like the first XXXXX:truncated to 900 characters. But then you need to take those leading 450 characters of the first block out and you do that by combining the two functions so to get the second block you do XXXXX:truncated to 900:truncated from end to 450 characters. Knowing that I think you can would out block three for yourself. I learnt this myself only a few days ago after been challenged to do so by @keith


Wow Thanks you so much! This works perfect! :slight_smile:

Exciting isn’t it, and so easy when you see how. Its a good idea to make this post as solved by checking the checkbox. That way people coming behind us will check it when they need a solution.


Yes it is! Do you also know how to capture if the sequence of 450 characters ends in a word?

So that the slices of 450 characters don’t begin or end in half words…

No idea @eddy. You may have to parse it for carriage returns or your sample appears to have headings, perhaps there is a way to parse for them. In truth, I have no idea. @keith you know this stuff, any ideas for @eddy?

1 Like

Well, I think you could truncate the string to 450 and then use regex search and replace to replace the last word with “ MORE…” or an ellipsis or something.

This is actually an interesting idea. Discussion of regex for “last characters” in string here:

Note that Bubble’s search & replace operator can take regex as the thing to match.

Not on my machine yet, but I might give this a go later. At any rate, the concept should work (and there are likely other approaches, but this is what came to my mind).

I have a soft spot for Regex so I can’t wait to see what you come up with.

Hey @patricia and @eddy: Here’s a way…

This results in:


It should be fairly obvious how this works, but if not, here’s an explanation:

  • We first truncate to roughly desired number of characters (105 in my example).
  • Because the character in that last position (105) may or may not be whitespace, I :trimmed the truncated string to remove any preceding/trailing whitespace. This ensures that last character is not whitespace.
  • Regex operator \s(\w+)$ matches the word at the very end of the string. We replace that by " MORE…" (yes there’s a space before the start of MORE). You could make that whatever you want, of course.

I’m sure this could be improved (like, there’s probably a REGEX that would handle the issue of the end of the string may or may not be whitespace – so perhaps one could get rid of the :trimmed operation), but this was just a quick-and-dirty experiment.

Anyway, solution above will work (and is actually pretty neat!) though it may not be the absolute best solution. I’m sure someone who’s more of a regex nerd could improve this.



aah thank you so much for the clear explanations @Keith & @patricia, but I can’t change the last word because it should match the next set of words/characters.

So the idea is to have sets of X characters that begin and end with a full word and then when you combine the sets it’s still readable :slight_smile: I think it could be done with Regex, but haven’t figured it out yet -_-

Sorry, all I was doing was skimming this thread after @patricia pinged me in it. Guess I misunderstood your question. I thought you guys were going on about truncating text VISUALLY.

(Which is a really common thing and my tip above is a pretty cool one for that.)

Seems you’re chunking some text in ways that I’m not 100% following. HOWEVER, while my tip is a little bit off-base, you can actually use it to help you. Instead of doing a search and replace to add a indicator like " More…" (in my example), you could actually use this to split a text right at a word boundary.

The index for where the split happened (in the original string) would then be the “:number of characters” of the new string, if you see what I’m saying.

Maybe that’s helpful to you.

Sorry, I’m unable to drill way down on this more. Basically, Bubble has all the basic (and advanced) string manipulation functions you might need for this, I think, but you’re gonna have to work out how to do it. (It may be a multi-step kind of thing where you may need to store some intermediate values in a custom state. You don’t have to force this all to happen in a single expression.)

No problem @keith! Your tips are very helpful :slight_smile:

I’ll let you know when I figured it out!

Thanks again :slight_smile:

1 Like

@eddy this is one of those times that finding a freelancer to write a bit of code will probably be the easiest way. However, it is still possible with the bubble text operators but as Keith says it will be multi-step. If you get the number of characters once you’ve done Keith’s procedure you will know how many less than 450 it is and that will tell you how many characters to add to the next chunk to ensure you pick up any word the Regex might have cut off. But doing it multiple times is going to be very very messy … it’s one of those times where ‘codeless’ makes life more difficult.

@patricia yes, I think you’re right… For now every X characters will do but in the future maybe its a good idea to get some code to do the job :smiley:


@patricia & @Keith I’ll share the app when it’s ‘testable’ so you can see what the use case is :smiley:

@patricia @keith UPDATE I fixed it, kind of…

You can now select a word that needs to be on the next slide:
And then a button will pop up

As you can see the word should be Surprised:

When you click the button it will save how many characters there are on the first slide and how many are selected, and then truncate to X the characters minus the selected ones.

And it will add the selected text to the next slide.

Still would be nice to have it automatically done, but this works fine too for now :smiley:

:+1: Now I see what you are doing, that makes sense. I’m no UX/UI expert but I’ve never seen that functionality before and I wonder about usability. Will it be unsettling and unfamiliar to users? Is there a reason to move from slide to slide instead of simply scrolling? I suspect the answer to that is yes.

Ha yes it will take some explanation I think… but yes it have to be slides. Part of the app is turning Blog posts into Stories, so the text-slides will be saved as an image, this is the preview :slight_smile:

Hmm. Well, in your example that you’ve now shown, consider this:

  • In that first slide, that regex I showed you will match “sur”.

So you can easily know:

  1. Where it is (end of slide 1’s string)
  2. What it is (“sur”)
  3. its length. (“sur”:number of characters)

How do you need any other info to just perform the operation for the user?

More to the point, actually, I think what you’re missing is that the original operation I showed you will always return a truncated string that (1) ends at a complete word and (2) has a length that is equal to or less than the number you set for the truncation value.