Skip to content

StringBuilder extension methods

Alex Kamsteeg edited this page Aug 8, 2015 · 3 revisions

Overview

SwissArmyKnife adds the following extension methods to StringBuilder:

AppendFormatLine()

Although the StringBuilder in System.Text has a AppendFormat() and a AppendLine() method it lacks a AppendFormatLine() method to add formatted lines. This means you have to use AppendFormat() or AppendLine() tricks to append new formatted lines:

var sb = new StringBuilder();

sb.AppendFormat("Lorem {0} dolor {1} amet {2}", "ipsum", "sit", Environment.NewLine);
// or
sb.AppendLine(string.Format("Lorem {0} dolor {1} amet", "ipsum", "sit"));

With SwissArmyKnife's AppendFormatLine() you can just do the following:

var sb = new StringBuilder();

sb.AppendFormatLine("Lorem {0} dolor {1} amet", "ipsum", "sit");

Clone this wiki locally