javascript StringBuilder
function StringBuilder(initialText)
{
this._parts = (typeof(initialText) !== 'undefined' && initialText !== null && initialText !== '') ?
[initialText.toString()] : [];
this._value = {};
this._len = 0;
this.append=function(text)
{
this._parts[this._parts.length] = text;
}
this.appendLine=function(text)
{
this._parts[this._parts.length] =
((typeof(text) === 'undefined') || (text === null) || (text === '')) ?
'\r\n' : text + '\r\n';
}
this.clear=function()
{
this._parts = [];
this._value = {};
this._len = 0;
}
this.isEmpty=function ()
{
if (this._parts.length === 0) return true;
return this.toString() === '';
}
this.toString=function (separator)
{
separator = separator || '';
var parts = this._parts;
if (this._len !== parts.length)
{
this._value = {};
this._len = parts.length;
}
var val = this._value;
if (typeof(val[separator]) === 'undefined')
{
if (separator !== '')
{
for (var i = 0; i < parts.length;)
{
if ((typeof(parts[i]) === 'undefined') || (parts[i] === '') || (parts[i] === null))
parts.splice(i, 1);
else
i++;
}
}
val[separator] = this._parts.join(separator);
}
return val[separator];
}
}
{
var sb =new StringBuilder("0");
sb.append("a");
sb.append("b");
sb.append("c");
sb.append("d");
alert(sb.toString(","));
}