Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: String Concatenation
From Wiki
Summary: An example of how strings can be concatenated with the StringBuilder class
If you concatenate a string like this:
- Dim s As String = ""
- s &= "This "
- s &= "is "
- s &= "an "
- s &= "example "
- Label1.Text = s
then you actually end up with 5 strings in memory rather than just the original one that you created. This obviously isn't very efficient.
Instead, you can use the System.Text.StringBuilder class which is both quicker and uses less memory as only one object is created:
- Dim sb As New StringBuilder
- sb.Append("This ")
- sb.Append("is ")
- sb.Append("an ")
- sb.Append("example")
- Label1.Text = sb.ToString()
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.