色尼玛亚洲综合影院,亚洲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類實現,轉載需保留來源!

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

主站蜘蛛池模板: 定州市| 汝南县| 伊川县| 温泉县| 永寿县| 社会| 清新县| 保定市| 高安市| 沁阳市| 剑河县| 绩溪县| 辉县市| 靖州| 安塞县| 邓州市| 阳城县| 桐梓县| 肃宁县| 平江县| 雅江县| 天津市| 阳曲县| 长岛县| 澄城县| 揭西县| 蕲春县| 衡阳市| 漯河市| 阿拉善左旗| 班玛县| 屯昌县| 鹤山市| 阿拉善右旗| 黄山市| 保康县| 乌海市| 浮山县| 宿迁市| 留坝县| 永胜县|