I have a String which can be very long so I want to split it in an array of Strings so in each position the string’s length should be lower than a specified number. The split can only be done in a white space or after a punctuation symbol, because I need that each fragments makes sense when it is read. It is something like a word processor so when the word doesn’t fit in the current line it goes to the next line.
I had thought in splitting the given String in the white spaces or punctuation symbols with a regular expression and the joining them controlling the length of the StringBuilder, but I think splitting in all the words and then joining them may not be very efficient.
What would be the most efficient way to perform this? Is there any library which could help in this job?
Thank you very much.
Here is something you can try:
Let’s say you have to split in strings that are at most n characters long.
I think this might be more efficient than splitting then joining your strings.