REPLACE sostituzione stringa






https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_replace

' Il replace()metodo non modifica la stringa su cui e' chiamato. Restituisce una nuova stringa.



<!DOCTYPE html>
<html>

<body>

<h2>JavaScript String Methods</h2>

<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo">Please visit Microsoft!</p>

<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace("Microsoft","W3Schools");
document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>


' pure

https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_replace_case


<!DOCTYPE html>
<html>
<body>

<h2>JavaScript String Methods</h2>

<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p>

<button onclick="myFunction()">Try it</button>

<p id="demo">Please visit Microsoft!</p>

<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace("MICROSOFT","W3Schools");
document.getElementById("demo").innerHTML = txt;
}
</script>

<p>The example does not work because MICROSOFT is written with upper case letters."</p>

</body>
</html>










( replacesostituzionestringa.html )- by Paolo Puglisi - Modifica del 17/12/2023