Thursday, May 26, 2011

StringBuilder clear method

String builder does not have a clear method, but if we want to add a clear method in stringbuilder use the following method in your utility class.

public static void Clear(this StringBuilder stringBuilder)
stringBuilder.Length = 0;
stringBuilder.Capacity = 16;

Benefit of this method is if we use same stringbuilder variable with clear the existing contents.