Lo snippet seguente utilizza una regular expression per la funzione replace per sostituire in una stringa gli spazi vuoti multipli con un singolo spazio.
La regular expression utilizzata è \s+
<html><head> <title>Replace spazi vuoi multipli</title> </head> <body> <textarea id="txtar"></textarea> <br> <input type="button" value="Mostra Selected Value" onclick="SelValue();" /> <script language="javascript" type="text/javascript"> function SelValue(){ var txt = document.getElementById("txtar"); var valore = txt.value.replace(/\s+/g," "); alert("Value: " + valore) } </script> </body> </html>
Download source javascript_replace_regurar_expresseion.html (437,00 bytes)
No comments yet.
Leave a comment