Lets say I have the following sentence:
A quick brown fox jumped over a lazy dog.
However I have a limit, that only 25 characters can be allowed in that sentence. This might leave me with something like:
A quick brown fox jum
However, that sentence doesn't make any grammatical sense, so I would prefer to find the last word which we can allow while staying in the 25 char limit. This will give us something like:
A quick brown fox
Which will be less than the 25 char limit, however it makes more grammatical sense. I.e the word isn't broken up, we have the maximum number of comprehensible words while staying in the limit.
How can I code a function which will take a string, and a char limit such as 25, and if the string exceeds the limit, returns the string with the max number of words possible?