Coding challenge I can't figure out

I’m trying to figure out how to code up a problem I’m facing. I’m creating an app that sends out text messages through the Twilio API and I’m grabbing the text message a user might input from a textarea on the front end. The way twilio works is that you can have up to 1600 characters, but every so often it cuts that into chunks because the most they can send in one chunk is 160 characters. So if there are less than 160 characters it keeps it as one chunk, if there’s MORE than 160 characters. Once you hit 160 characters, Twilio then allows each chunk to only be 153 characters! For example if the text length is 130 chars, it’s one chunk, if you get to 168 characters, you have two chunks, one is 153, the second is 15 characters (168-153). Here are the guidelines from Twilio if you’re interested in looking:,are%20limited%20to%2070%20characters.

What I’m trying to accomplish is when a user is typing in the textarea I want to use brackets to show where the chunk borders are. So while a user is typing and they are in the same situation as outlined earlier, I want it to look like this:

[153 chars] [15 chars]

If there are 326 characters I want it to look like this:

[153 chars] [153 chars] [20 chars]

Then when the text is saved to the back end I would want to strip out the brackets. I’m struggling to figure out how to write the logic for this puzzle. I would love some help on this one! Thanks :smiley:

maybe you could keep the string from textarea, and do not change that one that is sent to back-end

and display instead substrings of that one, each one surrounded by square brackets

so you do not need to them and then remove them - the brackets are part of display logic but not of logic for send to backend

Perfect, that’s a fantastic idea!! That saves me a lot of work.