When writing sentences to a console window, by default, the text will wrap at the exact width of the current window. Unless your sentences happen to consistently have word boundaries at exactly the same intervals as the window width, your text will wrap right in the middle words:
A while back, I created a small library that simplifies the syntax for writing messages to a console window called FluentConsole. It allows you to go from this:
Console.WriteLine("This is a string!");
"This is a string!".WriteLine();
And now, as of version
1.0.39 FluentConsole will automatically wrap long text strings by space-delimited word boundaries. By default, lines are wrapped according to the
BufferWidth of the current console window, but you can set the wrap width to any value. In the example below, the first sentence is wrapped at 25 characters while the second sentence is wrapped using the default 80 characters. The final sentence has line wrapping disabled altogether.
Setting this behavior is easy and can be changed in code at anytime, although I image that the default settings will suffice for the vast majority of applications.
var longString = "This is a really long string..."; FluentConsoleSettings.LineWrapOption = LineWrapOption.Manual; FluentConsoleSettings.LineWrapWidth = 25; longString.WriteLine(2); FluentConsoleSettings.LineWrapOption = LineWrapOption.Auto; longString.WriteLine(2); FluentConsoleSettings.LineWrapOption = LineWrapOption.Off; longString.WriteLine(2);
For more information on FluentConsole, check out its GitHub page. To use it in your application, either search for “FluentConsole” in Visual Studio’s NuGet package manager GUI or run the following command from the Package Manager Console: