Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the appropriate way to set a VB StringBuilder to an empty string?

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

like image 913
Wayne Werner Avatar asked Dec 08 '22 03:12

Wayne Werner


2 Answers

I usually just use:

str.Length = 0
like image 54
Chris Haas Avatar answered Dec 11 '22 09:12

Chris Haas


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

like image 21
Chris Dunaway Avatar answered Dec 11 '22 10:12

Chris Dunaway