toParagraph method

String toParagraph()

Formats the string as a paragraph with proper spacing and punctuation.

Joins multiple lines (split by newlines) into a single flowing paragraph, preserving sentence structure but removing leading/trailing whitespace.

Note: Does not add sentence-ending punctuation; use asSentence if that's needed.

Example:

'hello\nworld'.toParagraph()       // 'hello world'
'line1\nline2\nline3'.toParagraph() // 'line1 line2 line3'

Implementation

String toParagraph() {
  String retVal = '';
  List<String> sentences = split('\n');
  for (final String sentence in sentences) {
    retVal += ' ' + sentence;
  }
  return retVal.removeFirst(1);
}