//removespacefromitem / trim, trimleft, trimstart, trimright, polyfill old browsers TODO //- add polyfill to js or warning of compatibility function addspacetoitem(item,side='both',preventdoublepadding=1) { const space=' '; if(preventdoublepadding==1) { var dblspc=' '; var singlespc=' '; item=cleanvalue(item,dblspc,singlespc); item.trim(); } switch(side) { case 'left': newitem=space + item; break; case 'right': newitem=item + space; break; case 'both': newitem=space + item + space; break; case 'none': newitem=item; break; default: newitem=space + item + space; } return newitem; } function addspacetoitemsinarray(arrin,arrout) //ikke i brug, slettes? { var tempitem=null; for (var i = 0; i < arrin.length; i++) { tempitem=arrin[i]; if(i==(arrin.length-1)) { tempitem=addspacetoitem(tempitem,'none'); } else { tempitem=addspacetoitem(tempitem,'right'); } arrout.push(tempitem); } return arrout; } function lowestDivisibleByTwo(inputvalue) { // Ensure the input value is a number //TODO? remove inputvalue check? if (typeof inputvalue !== 'number' || isNaN(inputvalue)) { throw new Error('Input must be a valid number'); } // Calculate the lowest whole integer divisible by 2 let result=0; let rem=inputvalue % 2; if(rem==0) { result = inputvalue/2; } else { result = inputvalue-rem; } return result; } function cleanvalue(strvalue,srchstr,strreplce='') { var resultstr; resultstr = strvalue.replace(srchstr, strreplce); return resultstr; } function padvalue(strvalue,padoption='left',padstr=' ') { var resultstr; var tmpstr; tmpstr=strvalue.trim(); //trim before, to avoid double padding switch(padoption) { case 'left': tmpstr=padstr+tmpstr; break; case 'right': tmpstr=tmpstr+padstr; break; case 'both': tmpstr=padstr+tmpstr+padstr; break; default: tmpstr=padstr+tmpstr+padstr; break; } resultstr = tmpstr; return resultstr; } function analyseandsplitarray(resultarr,inputvalue) { function counthits(inputtext,item) { function reg2(input,flags) { input = regexEscape(input); return new RegExp("" + input + "", flags); } const re = reg2(item,'gi'); let text=inputtext; return ((text || '').match(re) || []).length } //var tmparr=[]; //1st search for character: " var item='\"'; var noofcharhits=0; var noofcharhitscounted=0; var spacearr=splitbyspace([],inputvalue.trim()); var quotedstr=''; var itemcount=0; var tmpvalue=''; var cleanedvalue=''; var collect=false; var iteminstr=false; if(counthits(inputvalue,item)>0) { noofcharhitscounted=counthits(inputvalue,item); } for (var i=0; i < spacearr.length; i++) { tmpvalue=spacearr[i]; if(noofcharhitscounted>1) { if(counthits(tmpvalue,item)>0) { itemcount++; iteminstr=true; collect=true; } if(collect==true) { cleanedvalue=cleanvalue(tmpvalue,item); cleanedvalue=padvalue(cleanedvalue); quotedstr+=cleanedvalue; } else { tmpvalue=padvalue(tmpvalue); resultarr.push(tmpvalue); } if((itemcount>0)&&(itemcount % 2==0)) { resultarr.push(quotedstr); itemcount=0; collect=false; iteminstr=false; } } else { tmpvalue=padvalue(tmpvalue); resultarr.push(tmpvalue); } } //var arrstr=resultarr.join(,); //arrstr=cleanvalue(arrstr,' ',' '); //resultarr=arrstr.split('); return resultarr; } function removestrfromstring(stringin,stringToRemove) { return newString = stringin.split(stringToRemove).join(""); } function ifnumberconvtostring(input) { if(isNaN(input)==true) { return input; } else { return '';//String(input); } } function removeBetweenStrings(str) { // Use regex to find the pattern between two identical strings //const regex = /(.*?)(.*<\/marker>)(.*)/ const regex = /(.*?)(\".*\")(.*)/; // Match the string with regex const match = str.match(regex); // If there's a match if (match) { // Extract the parts before, inside, and after the identical strings var before = ifnumberconvtostring(match[1]); const between = match[2]; var after = ifnumberconvtostring(match[3]); // Return an object with the modified string and the removed part return {modifiedString: before + after, removedString: between }; } else { // If no match found, return the original string and an empty removed string return {modifiedString: str, removedString: '' }; } return 'ost'; } // Example usage const exampleStr = 'This is the start middle part end.'; const //result = removeBetweenStrings(exampleStr); console.log('Modified String:', result.modifiedString); //console.log('Removed String:', result.removedString function splitbyspace(resultarr,stringdata) { const spacechar=' '; resultarr=stringdata.split(spacechar); return resultarr; } function writetodatastore(value) { var id='HIDDEN_datastore'; var obj=document.getElementById(id); obj.value=value; } function isObject(input) { const objectidentifier='object'; if(input==null) { return false; } if(typeof(input)==objectidentifier) { return true; } return null; //if check fails, deliberately return error } function existinarray(value,arr) { if (isObject(value)==true) { return null; //if check fails, deliberately return error } if(arr.includes(value)==true) //newer browser >2016 { return true; } if(arr.indexOf(value) > -1) //old browsers, IE9? { return true; } return false; } function addfirstitem(arr, result, firstitemindex) { let firstitem=arr[firstitemindex]; //firstitem=addspacetoitem(firstitem,'both'); let tempvalue=firstitem; if(existinarray(tempvalue,result)==false) { result.push(tempvalue); } return result; } function addnextitemtofirst(arr,result, firstitemindex) { let firstitem=arr[firstitemindex]; firstitem=addspacetoitem(firstitem,'both'); let nextitem=null; for (var i = firstitemindex+1; i < arr.length; i++) { nextitem=arr[i]; if(nextitem) { tempvalue=firstitem+nextitem; if(existinarray(tempvalue,result)==false) { result.push(tempvalue); } } } return result; } function existinstr(str,check) { res=false; if(str.search(check)>=0) { res=true; } return res; } function posinstr(str,check) { var res=str.search(check); if(res>=0) { return res; } return false; } function addtwonextitemstofirst(arr,result,firstitemindex) { let firstitem=arr[firstitemindex]; firstitem=addspacetoitem(firstitem,'both'); let nextitem1=null; let nextitem2=null; var tempvalue=null; for (var i = firstitemindex+1; i < arr.length; i++) { nextitem1=arr[i]; nextitem2=arr[i+1]; if(nextitem1 && nextitem2) { nextitem1=addspacetoitem(nextitem1,'right'); tempvalue=firstitem+nextitem1+nextitem2; if(existinarray(tempvalue,result)==false) { result.push(tempvalue); } } } return result; } function addthreenextitemstofirst(arr,result,firstitemindex) { let firstitem=arr[firstitemindex]; firstitem=addspacetoitem(firstitem,'both'); let nextitem1=null; let nextitem2=null; let nextitem3=null; var tempvalue=null; for (var i = firstitemindex+1; i < arr.length; i++) { nextitem1=arr[i]; nextitem2=arr[i+1]; nextitem3=arr[i+3]; if(nextitem1 && nextitem2 && nextitem3) { nextitem1=addspacetoitem(nextitem1,'right'); nextitem2=addspacetoitem(nextitem2,'right'); tempvalue=firstitem+nextitem1+nextitem2+nextitem3; if(existinarray(tempvalue,result)==false) { result.push(tempvalue); } } } return result; } function combineArrayItems(arr) { var result=[]; var tempitem=null; for (var i = 0; i < arr.length; i++) { //tempitem=arr[i]; //addspacetoitem(firstitem,'both'); //result.push(tempitem); result=addfirstitem(arr, result, i); result=addnextitemtofirst(arr,result,i); result=addtwonextitemstofirst(arr,result,i); result=addthreenextitemstofirst(arr,result,i); } return result; } function dontCombineArrayItems(arr) { var result=[]; var tempitem=null; for (var i = 0; i < arr.length; i++) { //tempitem=arr[i]; //addspacetoitem(firstitem,'both'); //result.push(tempitem); result=addfirstitem(arr, result, i); } return result; } function combineitemsinarr(arr) { var arrout=[] var tempitem; for (var i = 0; i < arr.length; i++) { tempitem=arr[i]; for (var j = i+1; j < arr.length; j++) { tempitem+=arr[j]; } arrout.push(tempitem); tempitem=''; } return arrout; } /*EOF*/