You could equally change this to a set of options, but passing blanks works fine too for optional ordered params:
http://jsfiddle.net/MHRbF/
<div id='test'></div>
<div id='test2'></div>
<div id='test3'></div>
Then in js:
function replaceMe(sString, sTarget, sWith, nCount){
if(!sString) return 'Please provide a string';
if(!sTarget) sTarget = /\s/;
if(!sWith) sWith= '<br/>';
if(!nCount) nCount = 1;
for(var c = 0; c < nCount; c++) sString= sString.replace(sTarget, sWith);
return sString;
}
x = 'Hello Crazy World Full of People!';
y = replaceMe(x);
document.getElementById('test').innerHTML = y;
y = replaceMe(x,'','',10);
document.getElementById('test2').innerHTML = y;
y = replaceMe(x,'','',2);
document.getElementById('test3').innerHTML = y;
You get the idea how this becomes pretty flexible.