String search







? Il search()metodo ricerca una stringa per un valore specificato e restituisce la posizione della corrispondenza:
? Esempio
? Utilizzare una stringa per eseguire una ricerca per "W3schools" in una stringa:

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript String Methods</h2>

<p>Search a string for "W3Schools", and display the position of the match:</p>

<p id="demo"></p>

<script>
var str = "Visit W3Schools!";
var n = str.search("W3Schools");
document.getElementById("demo").innerHTML = n;
</script>

</body>
</html>












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