String modules
Methods for String manipulation
by DiegoPacheco
HTML
<button id="bt_replaceAll">
Replace All
</button>
<div id="x">
</div>
CSS
button{
margin:15px
}
JavaScript
//modules
var strReplaceAll;
//replace all ocurrences of a String in other
/*
replaceAll = (str,old_str,new_str)=>{
if(!str.includes(old_str)) return str;
str=str.replace(old_str,new_str);
return replaceAll(str,old_str,new_str);
}
*/
strReplaceAll = (str,old_str,new_str)=>{
while(true){
if(!str.includes(old_str)) return str;
str=str.replace(old_str,new_str);
}
}
//tests
bt_replaceAll.onclick = ()=> x.innerHTML = strReplaceAll('blablabla','bla','ti');