How can I limit a string based on character count, and in the same time preserve complete words ?
I just don’t want to slice, but even want to preserve the complete words. Please guide me ..
Edit
Example
string = "stackoverflow rocks , I know it."
so I need a function, for example
limiter(string,5)
which should return a complete word (stackoverflow in this example), even if the limit I have set is 5. Thus preserving the meaning of words..
limiter(string,25)
desired result
stackoverflow rocks , I know
Thanks !
If what you want to do is word-wrapping a string then a simple approach is the following:
start + max_widthstartthen nothing can be done and just print out the whole line