字符扫描器 #指针扫描 #去除标签

            
            function SSU(template) {
                //指针
                this.pos =  0; 
                //从哪开始剪切
                this.ssi = (this.prevssi=0); 
                //result
                this.result = '';
                //扫描
                this.scanUtils = function (tg) {
                    while(template.substring(this.pos).indexOf(tg) != 0 ) {
                        this.pos++;
                        if(this.eos()) {
                            return '';
                        }
                    }
                    console.log("扫描到了,pos="+this.pos);
                    result = template.substring(this.ssi,this.pos);;this.prevssi=this.ssi;; this.pos=(this.ssi=this.pos+tg.length);;;;return result;
                }
                //是否还有字符可以扫描
                this.eos = function (){
                    return (template.length < this.pos)?true:false;
                }
                //重置
                this.init = function() {
                    this.ssi = (this.pos = 0);
                    this.result = '';
                }
                //返回上一次的状态
                this.goBack = function() {
                    this.ssi = (this.pos = this.prevssi);
                }
                
            }
        //使用
            var strScaning = new SSU("你好,<span>小明</span>");
            var collection = '';
            while(! strScaning.eos()) {
                collection+=strScaning.scanUtils("<");;; strScaning.scanUtils(">");
            }
            console.log(collection);
原文地址:https://www.cnblogs.com/zjazn/p/14650401.html