Click here to Skip to main content
15,879,474 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
21 Apr 2011CPOL 17.2K   2   7
Why not simply:markup = [];markup.push('');markup.push('');markup.push('');markup.push('');markup.push('Sample \'StringBuilder\' HTML');markup.push('');markup.push('');alert(markup.join('\n\r'));markup.toString() could...
Why not simply:

XML
markup = [];

markup.push('<html>');
markup.push('<head>');
markup.push('</head>');
markup.push('<body>');
markup.push('<h1>Sample \'StringBuilder\' HTML</h1>');
markup.push('</body>');
markup.push('</html>');

alert(markup.join('\n\r'));


markup.toString() could also be used if there is no need to add any separator. Uses native Javascript with no need for AJAX, or ASP.NET. Should therefore work cross-platform and cross-browser.

License

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


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: To follow the culinary model, why use a 'Death Star' to crac... Pin
gladtobegrey23-Apr-11 21:39
gladtobegrey23-Apr-11 21:39 
GeneralRe: I think I already answered your question. Yours is an altern... Pin
Albin Abel23-Apr-11 6:12
Albin Abel23-Apr-11 6:12 
GeneralReason for my vote of 5 Good solution. Pin
Prasanta_Prince22-Apr-11 3:26
Prasanta_Prince22-Apr-11 3:26 
GeneralReason for my vote of 5 Practical alternative with some good... Pin
AspDotNetDev21-Apr-11 10:51
protectorAspDotNetDev21-Apr-11 10:51 
GeneralTo answer your question "why not", the implementation of the... Pin
AspDotNetDev21-Apr-11 10:50
protectorAspDotNetDev21-Apr-11 10:50 
GeneralThe question "Why not" is not relevant. Your method has adva... Pin
Albin Abel21-Apr-11 7:19
Albin Abel21-Apr-11 7:19 
GeneralRe: No, my question is why create a dependency on ASP and AJAX a... Pin
gladtobegrey22-Apr-11 7:21
gladtobegrey22-Apr-11 7:21 

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.