Download presentation
Presentation is loading. Please wait.
1
JavaScript: Objects
2
Math Object
3
Math Object
4
Methods of the String Object
5
Methods of the String Object
6
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " 4 5 <!-- Fig. 12.4: CharacterProcessing.html --> 6 <!-- Character Processing Methods > 7 8 <html xmlns = " <head> <title>Character Processing Methods</title> 11 <script type = "text/javascript"> <!-- var s = "ZEBRA"; var s2 = "AbCdEfG"; 16 document.writeln( "<p>Character at index 0 in '" + s + "' is " + s.charAt( 0 ) ); document.writeln( "<br />Character code at index 0 in '" s + "' is " + s.charCodeAt( 0 ) + "</p>" ); 21 document.writeln( "<p>'" + String.fromCharCode( 87, 79, 82, 68 ) + "' contains character codes 87, 79, 82 and 68</p>" ) 25 document.writeln( "<p>'" + s2 + "' in lowercase is '" + s2.toLowerCase() + "'" ); document.writeln( "<br />'" + s2 + "' in uppercase is '" s2.toUpperCase() + "'</p>" ); // --> </script> 32 </head><body></body> 34 </html> CharacterProcessing.html Method charAt returns a string containing the character at the specified index (0 in this example). Method charCodeAt returns the Unicode value of the character at the specified index (0 in this example). Method fromCharCode takes a comma-separated list of Unicode values and builds a string containing the character representation of those Unicode values. Methods toLowerCase and toUpperCase display versions of String s2 in all lowercase and all upper case letters, respectively.
7
Program Output
8
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " 4 5 <!-- Fig. 12.5: SearchingStrings.html --> 6 <!-- Searching Strings > 7 8 <html xmlns = " <head> <title> Searching Strings with indexOf and lastIndexOf </title> 13 <script type = "text/javascript"> <!-- var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklm"; 17 function buttonPressed() { searchForm.first.value = letters.indexOf( searchForm.inputVal.value ); searchForm.last.value = letters.lastIndexOf( searchForm.inputVal.value ); searchForm.first12.value = letters.indexOf( searchForm.inputVal.value, 12 ); searchForm.last12.value = letters.lastIndexOf( searchForm.inputVal.value, 12 ); } // --> </script> 32 </head> SearchingStrings.html Method indexOf determines the first occurrence in the string letters of the string searchForm.inputVal.value. Method lastIndexOf determines the location of the last occurrence in letters of the string in text field inputVal.
9
SearchingStrings.html 34 <body>
<form name = "searchForm" action = ""> <h1>The string to search is:<br /> abcdefghijklmnopqrstuvwxyzabcdefghijklm</h1> <p>Enter substring to search for <input name = "inputVal" type = "text" /> <input name = "search" type = "button" value = "Search" onclick = "buttonPressed()" /><br /></p> 42 <p>First occurrence located at index <input name = "first" type = "text" size = "5" /> <br />Last occurrence located at index <input name = "last" type = "text" size = "5" /> <br />First occurrence from index 12 located at index <input name = "first12" type = "text" size = "5" /> <br />Last occurrence from index 12 located at index <input name = "last12" type = "text" size = "5" /></p> </form> </body> 53 </html> SearchingStrings.html
10
Program Output
11
Date Object
12
Date Object
13
Date Object
14
DateTime.html 1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " 4 5 <!-- Fig. 12.9: DateTime.html --> 6 <!-- Date and Time Methods --> 7 8 <html xmlns = " <head> <title>Date and Time Methods</title> 11 <script type = "text/javascript"> <!-- var current = new Date(); 15 document.writeln( "<h1>String representations and valueOf</h1>" ); document.writeln( "toString: " + current.toString() + "<br />toLocaleString: " + current.toLocaleString() + "<br />toUTCString: " + current.toUTCString() + "<br />valueOf: " + current.valueOf() ); 22 document.writeln( "<h1>Get methods for local time zone</h1>" ); document.writeln( "getDate: " + current.getDate() + "<br />getDay: " + current.getDay() + "<br />getMonth: " + current.getMonth() + "<br />getFullYear: " + current.getFullYear() + "<br />getTime: " + current.getTime() + "<br />getHours: " + current.getHours() + "<br />getMinutes: " + current.getMinutes() + "<br />getSeconds: " + current.getSeconds() + "<br />getMilliseconds: " + DateTime.html
15
DateTime.html 34 current.getMilliseconds() +
"<br />getTimezoneOffset: " + current.getTimezoneOffset() ); 37 document.writeln( "<h1>Specifying arguments for a new Date</h1>" ); var anotherDate = new Date( 2001, 2, 18, 1, 5, 0, 0 ); document.writeln( "Date: " + anotherDate ); 42 document.writeln( "<h1>Set methods for local time zone</h1>" ); anotherDate.setDate( 31 ); anotherDate.setMonth( 11 ); anotherDate.setFullYear( 2001 ); anotherDate.setHours( 23 ); anotherDate.setMinutes( 59 ); anotherDate.setSeconds( 59 ); document.writeln( "Modified date: " + anotherDate ); // --> </script> 54 </head><body></body> 56 </html> DateTime.html
16
Program Output
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.