本文主要跟大家分享js實作多個字串首尾重複進行拼接,字串數組,字串之間首尾重複,去除重複部分,進行拼接,希望能幫助到大家。
var j=0; var isRepeat = null var index = null var res = new Array() var tmp_key2 var tmp_key1 var Repeat = function(ary) { var arr1 = tmp = ary; for(var i=0; i<ary.length; i++){ tmp_key1 = ary[i]; var len1 = tmp_key1.length; ccc: for(j = 0 ; j<arr1.length; j++){ if(i===j){ continue; } tmp_key2 = arr1[j]; var len2 = tmp_key2.length; index = -1; var index_num =0; for(var k = 0; k < len2; k++) { var tmp_str = tmp_key2.slice(0,k+1); index = tmp_key1.indexOf(tmp_str); if(index !== -1){ isRepeat = index; } if( isRepeat != null && index ===-1 ){ break ccc; } } } // console.log(isRepeat); if(isRepeat !== null) { res.push(tmp_key1.slice(0,isRepeat)+tmp_key2) } index = null; isRepeat = null; } console.log(res); return res; } var ary = new Array("中国红","红红火火","zhanglei","lei@silenc","kkkzhang"); Repeat(ary);
["中国红红火火", "zhanglei@silenc", "kkkzhanglei"]
以上是js實作多個字串首尾重複拼接的詳細內容。更多資訊請關注PHP中文網其他相關文章!