elenat82
12/10/2015 - 10:35 AM

il metodo substr() in JavaScript.html

<html>
<head>
<title>il metodo substr() in JavaScript</title>
<script type="text/javascript">
	var testo = "Quel ramo del lago di Como che volge al tramonto";
	document.write("<p>Il primo carattere della stringa testo è '" + testo.substr(0, 1) + "'</p>");
	document.write("<p>I 5 caratteri a partire dal secondo della stringa testo sono '" + testo.substr(1, 5) + "'</p>");
	document.write("<p>I caratteri a partire dal decimo della stringa testo sono '" + testo.substr(9) + "'</p>");
	document.write("<p>L'ultimo carattere della stringa testo è '" + testo.substr(-1) + "'</p>");
	document.write("<p>Gli ultimi quattro caratteri della stringa testo sono '" + testo.substr(-4) + "'</p>");
	</script>
</head>
<body>
</body>
</html>