FlashSoft

网络飘逝了那么久,定定吧.........
随笔 - 5, 评论 - 3 , 引用 - 29

导航

公告

记录我所记,爱我所爱

存档

随笔分类

相册

链接

2004年9月7日

字符串链接类

<script language="JScript">
function StringBuilder(sString){//字符串连接操作类
   this.length=0;
   this.append=function(sString){
      this.length+=(this._parts[this._current++]=String(sString)).length;
      this._string=null;
      return this;
      }
   this.toString=function(){
      if(this._string!=null)
      return this._string;
      var s=this._parts.join("");
      this._parts=[s];
      this._current=1;
      return this._string=s;
      }
    this._current=0;
    this._parts=[];
    this._string=null;
    if(sString!=null)
    this.append(sString);
    }
var str=new StringBuilder();
str.append("a");
str.append("b");
alert(str.toString());
</script> 

posted @ 15:22 | Feedback (4)

京ICP备 05050892号