Monday, March 26, 2012

Stringbuilder Class

Could anyone show me the code that allows me reset a Stringbuilder back to
either null or nothing or a blank space?How about this?
sb.Length = 0
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
> Could anyone show me the code that allows me reset a Stringbuilder back to
> either null or nothing or a blank space?
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)
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> schreef in bericht
news:OUdAFyd9FHA.2640@.tk2msftngp13.phx.gbl...
> How about this?
> sb.Length = 0
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
>
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" <Paul@.discussions.microsoft.com> wrote in message
news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
> Could anyone show me the code that allows me reset a Stringbuilder back to
> either null or nothing or a blank space?
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" wrote:

> 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" <Paul@.discussions.microsoft.com> wrote in message
> news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
>
>

0 comments:

Post a Comment