Looking for best solution to create a number of sub-strings such that the length of each sub-string does not exceed the length value in parameter. It should converts spaces to specified separator(let's use comma as an example) when enclosed in sub-strings and removes extraneous spaces. Example:
input string = "Smoking is one of the leading causes of statistics"
length of substring = 7
result = "Smoking,is one,of the,leading,causes,of,statist,ics."
input string = "Let this be a reminder to you all that this organization will not tolerate failure."
length of substring = 30
result = "let this be a reminder to you,all that this organization_will not tolerate failure."