Click here to Skip to main content
13,260,108 members (45,416 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 17 Apr 2011

Javascript StringBuilder for Beginners (ASP.NET 3.5 and above)

, 18 Apr 2011
Rate this:
Please Sign up or sign in to vote.
Just a simple note with sys.StringBuilder which is just beginner level
Just a beginner tip. Many programmers still use string concatenations in the classical way. An example situation like this - Adding and deleting div dynamically in JavaScript[^]

Are JavaScript strings mutable? NO. So what is the best way to concatenate strings in JavaScript like runtime markup generation, etc? The .NET way is to use StringBuilder. From Framework 3.5, it is available through the Microsoft Ajax Library. Enable Ajax in the page by using a ScriptManager. Now the Sys.StringBuilder class is available for use.
<asp:ScriptManager ID="script1" runat ="server">

In Javascript:
var sb = new Sys.StringBuilder();
sb.append("Hello ");
sb.append("World ");

How does a string builder do concatenation efficiently? It uses an array to hold the strings, then uses the Array.Join to concatenate the strings. So intermediate string generations are avoided.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Albin Abel
Software Developer
India India
I am developer in .Net and GIS.

You may also be interested in...

Comments and Discussions

GeneralCross browser Pin
Steve Wellens16-Apr-11 5:58
memberSteve Wellens16-Apr-11 5:58 
GeneralRe: Cross browser Pin
Albin Abel16-Apr-11 6:10
memberAlbin Abel16-Apr-11 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 18 Apr 2011
Article Copyright 2011 by Albin Abel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid