There is no built-in method for this. You can use regex:
string text = "The quick brown fox jumps over the lazy dog."; int minLength = 1; int maxLength = 20; MatchCollection lines = Regex.Matches(text, "(.{"+minLength.ToString()+","+maxLength.ToString()+"})(?: |$)|([^ ]{"+maxLength.ToString()+"})"); StringBuilder builder = new StringBuilder(); foreach (Match line in lines) builder.AppendLine(line.Value); text = builder.ToString();
Note: I fixed pangram .
Guffa source share