Stringbuilder Class

G

Guest

Could anyone show me the code that allows me reset a Stringbuilder back to
either null or nothing or a blank space?
 
E

Edwin Knoppert

Yes, just tested but my comp. is incr. slow at home.
Dim sb As New StringBuilder

sb.Append("Hello")

MsgBox(sb.ToString)

sb.Length = 0

MsgBox(sb.ToString)
 
K

Ken Cox

Hi Paul,

It looks like you can set the Length to zero or just use New again.

Here's a little demo:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
sb.Append("!", 50)
sb.Append(": Length is now " & sb.Length.ToString)
Label1.Text = sb.ToString
sb.Length = 0
Label2.Text = "After Length=0:" & sb.ToString
sb = New StringBuilder
End Sub

Ken
Microsoft MVP [ASP.NET]
 
G

Guest

Actually, I tried using New again and that did not seem to work.

Setting the length to 0 did work.

Thank you for your assistance.






Ken Cox said:
Hi Paul,

It looks like you can set the Length to zero or just use New again.

Here's a little demo:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
sb.Append("!", 50)
sb.Append(": Length is now " & sb.Length.ToString)
Label1.Text = sb.ToString
sb.Length = 0
Label2.Text = "After Length=0:" & sb.ToString
sb = New StringBuilder
End Sub

Ken
Microsoft MVP [ASP.NET]



Paul said:
Could anyone show me the code that allows me reset a Stringbuilder back to
either null or nothing or a blank space?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top