作家
登录

javascript StringBuilder类实现

作者: 来源:www.28hudong.com 2013-03-30 02:47:43 阅读 我要评论

复制代码 代码如下:// 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绘图 JavaScript绘图 如果需要在网页上提供图形化的资料,通常是将其制作成图片,但这样一来网络上的开销就太大了。有什么办法呢?这里向你提供一组JavaScript函数,来解决这一>>>详细阅读


本文标题:javascript StringBuilder类实现

地址:http://www.17bianji.com/kaifa2/JS/29102.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)