色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript StringBuilder類實現

復制代碼 代碼如下:
// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
this.strings = new Array("");
this.append(value);
}
// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
if (value)
{
this.strings.push(value);
}
}

// Clears the string buffer

StringBuilder.prototype.clear = function ()
{
this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
return this.strings.join("");
}

代碼看上去很簡單直接。實際上就是用array,push,join等來實現,以下是如何使用該類
復制代碼 代碼如下:
// create a StringBuilder
var sb = new StringBuilder();
// append some text
sb.append("Some of those preparing for international ");
sb.append("exams such as the TOEFL ");
sb.append("need extra practice for the listening section");
// get the full string value
var s = sb.toString();
alert(s);

非常簡單,不需要太多的說明。如果你在.NET中用了StringBuilder,你也會知道這里如何用。

JavaScript技術javascript StringBuilder類實現,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 绿春县| 哈巴河县| 宾川县| 曲松县| 修水县| 山阳县| 西和县| 达孜县| 揭阳市| 韶关市| 双柏县| 鸡东县| 乐都县| 元氏县| 岳普湖县| 苍梧县| 庆云县| 从江县| 汕头市| 保山市| 阿克陶县| 赤峰市| 兴仁县| 长宁县| 象州县| 望城县| 诸暨市| 莫力| 云安县| 盐山县| 鹤山市| 辛集市| 田林县| 沙河市| 荔浦县| 三台县| 卓尼县| 鄂伦春自治旗| 德惠市| 兴和县| 双城市|