Why use StringBuilder explicitly if the compiler converts string concatenation to a StringBuilder automatically? [duplicate]

As you mention, you should not use StringBuilder instead of a simple string concatenation expression such as a + ” = ” + b. The latter is faster to type, easier to read, and the compiler will use a StringBuilder internally anyway so there is no performance advantage by rewriting it. However StringBuilder is useful …

Read more

How to remove empty lines from a formatted string

If you also want to remove lines that only contain whitespace, use resultString = Regex.Replace(subjectString, @”^\s+$[\r\n]*”, string.Empty, RegexOptions.Multiline); ^\s+$ will remove everything from the first blank line to the last (in a contiguous block of empty lines), including lines that only contain tabs or spaces. [\r\n]* will then remove the last CRLF (or just LF …

Read more