﻿
function stringBuilder() {
    var me = this;

    this.chunks = new Array("");

    this.append = function(val) {
        me.chunks.push(val);
        return;
    };

    this.clear = function() {
        me.chunks.lengh = 1;
    };

    this.toString = function() {
        return (me.chunks.join(""));
    };
}


String.prototype.replaceAll = function(strMatch, strReplace) {
    s = this;
    count = 0;
    while ((s.indexOf(strMatch) >= 0) && (count++ < 1000)) {
        s = s.replace(strMatch, strReplace);
    }
    return (s);
};

String.prototype.count = function(strMatch) {
    var me = this;
    var count = 0;
    var pos = 0;
    while (((pos = me.indexOf(strMatch, pos)) >= 0) && (count < 1000)) { count++; }
    return (count);
};


String.prototype.chop = function(max) {
    var me = this;
    if (me.length < max) { return (me); }
    return (me.substr(0, max) + "...");
};

//-----------------------------------------------------------------
//	Array object forEach Prototype
//
//    Description:   This prototype adds the forEach functionality 
//                   to the Array object
//
//    Usage:   Array.forEach(function_pointer);
//-----------------------------------------------------------------

if (!Array.prototype.forEach) {
    Array.prototype.forEach = function(fun /*, thisp*/) {
        var len = this.length;
        if (typeof fun != "function")
            throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this)
                fun.call(thisp, this[i], i, this);
        }
    };
}


String.prototype.stripHTML = function() {
    // What a tag looks like
    var matchTag = /<(?:.|\s)*?>/g;
    // Replace the tag
    return this.replace(matchTag, "");
};
