领星动网编程开发之爆炸小宇宙

cnitblog.com/lxasp - - 有一种信念叫做编程
posts - 61, comments - 34, trackbacks - 0, articles - 0
    var chsSplitSize = function(inputstr,size) {
        var inarr = inputstr.split(""),strcurr,strnext,asccurr,ascnext,posonebase=0,lastzerobase=0,chsnext=false,i,j,k=0,ou=[],s;
        inarr.push("");
        for(i=0;i<inarr.length-1;i++){
            strcurr=inarr[i];strnext=inarr[i+1];
            try {
                asccurr = strcurr.charCodeAt(0);
                ascnext = strnext.charCodeAt(0);
            } catch (e) {};
            if (asccurr > 255){
                posonebase+=2;
            }else{
                posonebase++;
            };
            if (ascnext > 255){
                chsnext=true;
            }else{
                chsnext=false;
            };
            if(chsnext&&(posonebase-lastzerobase)==(size-1)){
                s="";
                for(j=k;j<=i;j++){
                    s+=inarr[j];
                }
                k=i+1;
                lastzerobase=posonebase;
                if(s.length>0)ou.push(s);
            }else if((posonebase-lastzerobase)==size){
                s="";
                for(j=k;j<=i;j++){
                    s+=inarr[j];
                }
                k=i+1;
                lastzerobase=posonebase;
                if(s.length>0)ou.push(s);
            }
        }
        if((posonebase-lastzerobase)<=size){
            s="";
            for(j=k;j<=i;j++){
                s+=inarr[j];
            }
            k=i+1;
            lastzerobase=posonebase;
            if(s.length>0)ou.push(s);
        }
        return ou;
    };
//                             123456789012345678901
    var s="",arr=chsSplitSize("一二三234我的额1额56789四五六七",12);

    for(var i=0;i<arr.length;i++){
        s+='<div>'+arr[i]+'</div>\n';
    }
    alert(s);
只有注册用户登录后才能发表评论。