<!-- JavaScript:Strings code snippet 4. -->
<!-- Create a string, use property 'length', 
together with methods 'charAt()' and 'charCodeAt()' -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
<!--
/* create an string called 'myString' */
var myString="John.Smith@www.com";
document.write("The string we are using as a test is: "+myString+"<br />");
/* use 'String' object property 'length' and assign to variable */
// 'length' returns the length of the string
var lengthMyString=myString.length;
/* write out these values */
document.write("The number of characters in myString is: "+lengthMyString+"<br />");
/* introducing 'charAt()' which returns a character at a 
specified index position */
document.write("The last character in myString is: "+myString.charAt(lengthMyString-1)+"<br />");
/* introducing 'charCodeAt()' which returns Unicode value of a 
character at a specified index position */
document.write("The Unicode value of this character is: "+myString.charCodeAt(lengthMyString-1));
// -->
</script>

</body>
</html>