AdvWeb-1/14 DePaul University SNL 262 Advanced Web Page Design Chapt 6 - Strings & Arrays Instructor: David A. Lash.

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
EIW: Javascript the Language1 The JavaScript Language.
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
1 The Information School of the University of Washington Oct 30fit review Programming Review INFO/CSE 100, Fall 2006 Fluency in Information Technology.
Questions ? 1. JavaScripts have to be compiled before they are executed. True/False 2. What is the main advantage to interpreted languages? You don’t have.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
AdvWeb-1/14 DePaul University SNL 262 Advanced Web Page Design Chapt 8 - Looping Instructor: David A. Lash.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
6.1 JavaScript Objects and Object- Oriented Programming (OOP)
AdvWeb-1/29 DePaul University SNL 262 Advanced Web Page Design Introduction To JavaScript - II Instructor: David A. Lash.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Chapt 7 - Conditional Statements - IV Instructor: David A. Lash.
AdvWeb-1/11 DePaul University SNL 262 Advanced Web Page Design Supplemental - 3 Additional Examples Instructor: David A. Lash.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Introduction to scripting
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Scripting Languages.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Topic: An Introduction to JavaScript - from Beginning JavaScript by Wilton (WROX)
INE1020: Introduction to Internet Engineering 3: Web Page Authoring1 Lecture 6: Introduction to Javascript II r Javascript Objects Array String Date Math.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
M. Taimoor Khan Javascript Objects  Every data-type defined in Javascript is an object  It has a class definition for.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
Pascal Programming Arrays and String Type.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
Unit 12 JavaScript Arrays Instructor: Brent Presley.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
Chapter 12: Objects CIS 275—Web Application Development for Business I.
Array Declarations Arrays contain a fixed number of variables of identical type Array declaration and allocation are separate operations Declaration examples:
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Two Dimensional Arrays Found in chapter 8, Section 8.9.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
OVERVIEW OF CLIENT-SIDE SCRIPTING
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JavaScript: A short introduction Joseph Lee Created by Joseph Lee.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.
CHAPTER 4 DECISIONS & LOOPS
>> Introduction to JavaScript
Microsoft Visual Basic 2005: Reloaded Second Edition
JavaScript Objects.
Basics of JavaScript Programming Language
JavaScript Syntax and Semantics
Visual Basic .NET BASICS
T. Jumana Abu Shmais – AOU - Riyadh
M150: Data, Computing and Information
Arrays Part 2.
JavaScript: Objects.
Presentation transcript:

AdvWeb-1/14 DePaul University SNL 262 Advanced Web Page Design Chapt 6 - Strings & Arrays Instructor: David A. Lash

AdvWeb-2/14 Chapt 6 - String Types u You can store numbers or characters into variables. u For example, x=12; or x="Dave"; u JavaScript allows 2 different ways to assign a set of characters into a variable: x = "Dave"; or x = new String("Dave"); u These 2 assignments are equal. The 2nd explicitly creates a new object called string and assigns into it the initial value called Dave. u JavaScript allows either assignment. The second is much closer to the Java string definition and assignment.

AdvWeb-3/14 Manipulating Strings u Simple assignment statements can be used to alter string values in JavaScript. u The "+" sign is used to concatenate two strings together: x = new String("Dave"); y = "Tom"; x = y; y = y + x; document.write("x=", x, " " ); document.write("y=" + y + " ");

AdvWeb-4/14 Using Strings u A string is an object u Objects have properties and behaviors u Properties are attributes you can look at - Access properties via object_name.property. – For example, strings have length test=“A String”; document.write(test.length); u Behaviors are functions for the object - Access properties via object_name.property. – For example, functions available for u toUpperCase() - converts string to all upper case u toLowerCase() - converts string to all lower case test=“A String”; document.write(test.toLowerCase());

AdvWeb-5/14 Using Strings - Substrings u Here is another behavior for string objects – text.substring(3,6); – returns the portion of string text starting at 3 and ending at 6 – So text=“Apple” text.substring(1,2); returns “A”

AdvWeb-6/14 Strings Example: u A more complete example... Example String x = window.prompt(“Enter a String”); document.write(x.length, “ ”); document.write(x.toUpperCase(), “ ”); document.write(x.toLowerCase(), “ ”); See: stringtoUpper.html

AdvWeb-7/14 Another String Function u Here is yet another behavior – location = test.indexOf( “Dave”); – searches for the string “Dave” in the string test and returns the positional value value if it is in there. – Returns -1 if not there. Example String x = window.prompt("Enter a String"); document.write(x.indexOf("Dave"), " "); document.write("String was=", x); See: /examples/stringtoIndex.htmlexamples/stringtoIndex.html

AdvWeb-8/14 Introduction To Arrays u Arrays are a way to group sets of data items as a single unit: u First you declare the size of array (or number of items you want to group together) scores = new Array(30); scores[0] = 39; scores[1] = 40; scores[2] = 55; scores[3] = 99; average=(scores[0]+scores[1]+scores[3]+scores[2])/4; document.write( “average=“, average ); u Arrays have many advantages that we will look at some now (and others when we look at looping). - e.g., x=scores[1+1]; Variable name Subscript

AdvWeb-9/14 Creating Arrays u var a new Array(); – creates an empty array with no elements u var a new Array(5, 4, 3, 2, 1); – creates an array with 5 elements and initializes them. u var a = new Array(10); – creates an array of 10 elements each set with the undefined value and sets length property to 10.

AdvWeb-10/14 An Array Example Example String Sample Array ; numb = new Array(5); numb[0]=window.prompt("Enter Number 0"); numb[1]=window.prompt("Enter Number 1"); numb[2]=window.prompt("Enter Number 2"); numb[3]=window.prompt("Enter Number 3"); numb[4]=numb[0]*1+1; index = window.prompt("Enter an index number from 0-4"); if ( index = 0 ) { document.write("Your index was " + index + " "); document.write("The Array element was " + numb[index] + " "); } else document.write("I said a number between 0-5 " ); See:: examples/ 5_arrayexample1.html

AdvWeb-11/14 Some array procedures & methods u length var a = new Array(10); x=a.length; u sort() var a = new Array(1, 33, 12, 4, 0); a.sort(); u reverse() var a = new Array(1, 44, 2, 4); a.reverse();

AdvWeb-12/14 Another Array Example Example String Sample Array ; var a = new Array(1, 33, 12, 4, 0); for (i=0; i<a.length; i++ ) { document.write("presort = item number" + i + "=" + a[i] + " "); } document.write(" "); a.reverse(); for (i=0; i<a.length; i++ ) { document.write("reverse item number" + i + "=" + a[i] + " "); } document.write(" "); a.sort( ); for (i=0; i<a.length; i++ ) { document.write("post sort item number" + i + "=" + a[i] + " "); } See:: examples/ 5_arrayexample2.html

AdvWeb-13/14 String Arrays u Split: splits a string from 1 string into an array of different parts: – testname=“David A. Lash”; – parts=testname.split(“ “); u Example: Example String Test String Split ; testname = "David A. Lash"; parts = testname.split(" "); document.write( parts[2], ", ", parts[0], " ", parts[1], " " ); See: StringS plit.html StringS plit.html

AdvWeb-14/14 Scrolling Example Scrolling Message Example var msg = "This is an example of a scrolling message. Isn't it exciting?"; var spacer = "......"; var pos = 0; function ScrollMessage() { window.status = msg.substring(pos, msg.length) + spacer + msg.substring(0, pos); pos++; if (pos > msg.length) pos = 0; window.setTimeout("ScrollMessage()",200); } ScrollMessage(); Scrolling Message Example Look at the status line at the bottom of this page. (Don't watch it too long, as it may be hypnotic.) See: croll.html