piccolo esempio pratico

<script>
str = "stringa con spazi";
str = str.replace(/ /g,"%20");
alert(str);
</script>

ciao!