In Java or Groovy is there a library or a simple implementation that for a text it would create substring at some length but not breaking a word in the middle?
An example method with an input: substring("My very long text", 9 /*substring length*/, true /*break on whole words only*/)
An output because without keeping the words it would result in My very l
. Since I want to break on the whole words only it will be My very
.
In case there are no spaces it would cut the string at the index:
substring("MyVeryLongText", 9 /*substring length*/, true /*break on whole words only*/)
--> MyVeryLon