JavaScript实现StringBuilder

StringBuilder = function (initialText) {
    this._array = (typeof (initialText) !== 'undefined' && initialText !== null && initialText !== '') ? [initialText] : [];
    this.append = function (text) {
        this._array[this._array.length] = text;
    }
    this.appendLine = function (text) {
        this._array[this._array.length] = ((typeof (text) === 'undefined') || (text === null) || (text === '')) ? '\r\n' : text + '\r\n';
    }
    this.clear = function (text) {
        this._array = [];
    }
    this.isEmpty = function () {
        return (this._array.length == 0 ? true : false);
    }
    this.toString = function (separator) {
        separator = separator || ''
        var array = this._array;
        if (separator !== '') {
            for (var i = 0; i < array.length; ) {
                if ((typeof (array[i]) === 'undefined') || (array[i] === '') || (array[i] === null)) {
                    array.splice(i, 1);
                }
                else {
                    i++;
                }
            }
        }
        return array.join(separator);
    }
    this.indexOf = function (searchvalue) {
        return this._array.indexOf(searchvalue);
    }
    this.contains = function (text) {
        return this._array.contains(text);
    }
}
—— 完 ——
相关推荐
评论

立 为 非 似

中 谁 昨 此

宵 风 夜 星

。 露 , 辰

文章点击榜

细 无 轻 自

如 边 似 在

愁 丝 梦 飞

。 雨 , 花