1. 程式人生 > >js 給字串切片重組

js 給字串切片重組

目的:將傳過來的字串進行重組用decodeURI解析

	function test(string,num){
		var temp='';
		for (i=0;i<string.length;){			
			a=string.substr(i,num);
			if ((i+num)>string.length){
				alert('dayu');
				a=string.substring(i,string.length);
				i=string.length;
				temp+=decodeURI(a);
				}
			else if((num-a.lastIndexOf("%"))<3){
				//alert('xiaoyu');
				b=a.lastIndexOf('%');
				a=string.substr(i,b);
				alert(a);
				temp+=decodeURI(a);
				
				i+=b;
				}
			else{
				temp+=decodeURI(a);
				i+=num;
				}
			
			}
		}

由於傳過來的為encodeURI字串,所以要切片而且確定不能講%12 這樣的分割。

沒有太大意義,但是進入了誤區,以為decodeURI不能解析大量字串,所以做了這個