How can I set a VB StringBuilder to an empty string?

I use VB StringBuilder and I was curious what is considered “best practice” to empty the linker / set it to a new line. It would be 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

+4
source share
2 answers

I usually use:

 str.Length = 0 
+8
source

In .Net 4, they added the Clear method for this purpose.

+6
source

Source: https://habr.com/ru/post/1310251/


All Articles