The title might be confusing. Just say I have a newspaper article. I want to cut it off around a certain point, say 4096 characters, but not in the middle of a word, rather before the last word that takes the length over 4096. Here is a short example:
"This is the entire article."
If I want to cut it off before a word that takes the total length over 16 characters, here is the result I would want:
"This is the entire article.".function
=> "This is the"
The word “entire” takes the total length over 16, so it must be removed, along with all characters after it, and the space before it.
Here is what I don’t want:
"This is the entire article."[0,15]
=> "This is the ent"
It looks easy in writing, but I don’t know how to put it into programming.
How about something like this for your example: