没有合适的资源?快使用搜索试试~ 我知道了~
javascript StringBuilder类实现
0 下载量 62 浏览量
2020-12-09
17:27:04
上传
评论
收藏 22KB PDF 举报
温馨提示
试读
1页
代码如下:// 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
资源详情
资源评论
资源推荐
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,你也会知道这里如何用。
weixin_38649356
- 粉丝: 5
- 资源: 951
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0