Given: string S, number N. It is necessary to break the string into substrings so that
- Splitting occurred at spaces (the space itself is removed)
- The length of each substring does not exceed N characters except for the case when 1 word is more than N characters, then it is not broken.
Example: S = "One two three big long". N = 6
Output: "One", "two", "three", "large".
I need this algorithm to place a long line in a limited column of a table.
Apparently, this needs to be done using regular expressions, but I can't find the right one.