views:

39

answers:

2

I'm using VB's StringBuilder, and I was curious what is considered "best practice" for emptying the builder/setting it to a new string. Would it be something like this:

Dim str As New System.Text.StringBuilder()
str.Append("Some string to remove")
str = new System.Text.StringBuilder()
str.Append("Ahh, fresh new text!")

or is there a "Better" way?

Thanks

+3  A: 

I usually just use:

str.Length = 0
Chris Haas
This is my prefered method
Ben
That makes sense, and looks a lot cleaner to boot!
Wayne Werner
+3  A: 

In .Net 4, they have added a Clear method for that purpose.

Chris Dunaway