Description
The CollapseSpacesAndPreserveLines
method is a static extension method provided by the SandboxSystemExtensions
class. It processes a given string by collapsing consecutive whitespace characters into a single space while preserving line breaks. This is useful for normalizing text input where you want to maintain the structure of paragraphs but reduce unnecessary spaces.
Usage
To use the CollapseSpacesAndPreserveLines
method, simply call it on any string instance. This method is an extension method, so it can be called as if it were a method on the string
class.
Example usage:
string input = "This is a test.\n\nThis is another line.";
string result = input.CollapseSpacesAndPreserveLines();
// result: "This is a test.\n\nThis is another line."
Example
string input = "This is a test.\n\nThis is another line.";
string result = input.CollapseSpacesAndPreserveLines();
// result: "This is a test.\n\nThis is another line."