' bstring()e' simile a slice(). ' differenza e' che substring()non puo' accettare indici negativi. ' Se si omette il secondo parametro, substring()verra' troncato il resto della stringa. https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_substring <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.substring(7,13); document.getElementById("demo").innerHTML = res; </script> </body> </html> ' pure SUBSTR https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_substr <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.substr(7,6); document.getElementById("demo").innerHTML = res; </script> </body> </html> ' pure senza secondo parametro, tronca la frase https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_substr1 <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.substr(7); document.getElementById("demo").innerHTML = res; </script> </body> </html> ' con parametro negativo https://www.w3schools.com/js/tryit.asp?filename=tryjs_string_substr2 <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The substr() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> var str = "Apple, Banana, Kiwi"; var res = str.substr(-4); document.getElementById("demo").innerHTML = res; </script> </body> </html> |