JavaScript Chapter 7 Working with Strings. String Operations (Chap 2) var colors = red blue; var colors = red blue; var sizes = small large; var sizes.

Slides:



Advertisements
Similar presentations
9 Copyright © 2005, Oracle. All rights reserved. Using Strings, String Buffer, Wrapper, and Text-Formatting Classes.
Advertisements

Intro to Javascript CS Client Side Scripting CS380 2.
Java
Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
Web Application Development Muhammad Ali Versonic Pte Asher Imtiaz Forman Christian College.
1 CS101 Introduction to Computing Lecture 41 Images & Animation (Web Development Lecture 14)
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Java Strings in 10 minutes
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Fundamental Programming Structures in Java: Strings.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
1 CS101 Introduction to Computing Lecture 38 String Manipulations (Web Development Lecture 13)
Mrs. Smith’s 7th Grade Reading Blue Class Mrs. Smith’s 7th Grade Reading Blue Class Mrs. Smith’s 7th Grade Reading Blue Class.
Chapter 31 Fundamentals of Programming in Visual Basic (Continue VI) String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123.
2 Alerts and the If/Else Conditional Statement CONTINUED There's No Right Way to Do It There are, literally, a million ways to write any given script.
Scripting Languages.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Chapter 3 : Processing on the Front End JavaScript Technically its name is ECMA-262, which refers to the international standard which defines it. The standard.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
String Object.  Conundrum: I would like people to have more time on the revisions…  … but I don't have a lot of time myself for more grading  A1 Revision.
How to Work with Numeric and String Data
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
The Grammar of JavaScript.  Each line of a script is a statement  An instruction that JavaScript can evaluate (make sense of)  Ends with a semicolon;
CS346 Javascript -3 Module 3 JavaScript Variables.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2.
Chapter 7: Characters, Strings, and the StringBuilder.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
1 Microsoft® Visual Basic®.NET Language # 1. 2 Variable Declaring Variable Dim {VariableName} As {Type} Dim {VariableName} As {Type} = {value} Example:
Working with Strings. Learning Objectives By the end of this lecture, you should be able to: – Appreciate the need to search for and extract information.
JavaScript Assignment Statements Expressions Global Functions CST 200 JavaScript.
CSC Programming I Lecture 9 September 11, 2002.
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
Chapter 12: Objects CIS 275—Web Application Development for Business I.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
Lab String Concatenation String s3 = s1.concat(s2); String s3 = s1 + s2; s1 + s2 + s3 + s4 + s5 same as (((s1.concat(s2)).concat(s3)).concat(s4)).concat(s5);
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.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Strings Robin Burke IT 130. Outline Objects Strings methods properties Basic methods Form validation.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Basic Objects. Math Object  Math.cos( x ), x in radians  Math.sqrt ( x )  Math.pow ( x, y )  Math.ceil( x )  etc.
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.
Introduction to Calculated Columns Variables, Conditionals, and String Manipulation PRESENTER: Cameron Blashka| Informer Implementation Specialist| April.
Strings, StringBuilder, and Character
JavaScript Objects.
Chapter 7: Strings and Characters
String, Math & Miscellaneous Methods & Properties
Exposure Java 2015 Pre-AP®CS Edition Chapter 12 Slides String Methods
Variables Kevin Harville.
12.4 p 471 a) double[] number = {1.05, 2.05, 3.05, 4.05, 5.05};
What Color is it?.
Building Java Programs
JavaScript: Objects.
Exam Prep.
The Web Wizard’s Guide To JavaScript
String, Math & Miscellaneous Methods & Properties
Murach's JavaScript and jQuery (3rd Ed.)
What We Want To Do User enters: Mary Smith
Presentation transcript:

JavaScript Chapter 7 Working with Strings

String Operations (Chap 2) var colors = red blue; var colors = red blue; var sizes = small large; var sizes = small large; colors += green orange; colors += green orange; sizes = sizes + medium XXXL; sizes = sizes + medium XXXL; The following are true: The following are true: –(colors == red blue green orange) –(sizes == small large medium XXXL) –(one < two) //alphabetical ordering –(ten > five) //alphabetical ordering

Substring Functions (Chap 7) var apple = Macintosh; var apple = Macintosh; (apple.length == 9) (apple.length == 9) (apple.charAt(0) == M) (apple.charAt(0) == M) (apple.charAt(8) == h) (apple.charAt(8) == h) (apple.indexOf(t) == 5) (apple.indexOf(t) == 5) (apple.indexOf(x) == -1) (apple.indexOf(x) == -1) (apple.substring(3, 5) == in) (apple.substring(3, 5) == in) (apple.substr(3, 2) == in) (apple.substr(3, 2) == in)

Numbers in Strings (Chap 7) alert ( a ); is really alert (a.toString()); alert ( a ); is really alert (a.toString()); –.toString() converts any variable to a string –In most cases, JavaScript does this automatically parse functions convert strings to numbers parse functions convert strings to numbers –var str = 66.6 percent; –(parseInt(str) == 66) –(parseFloat(str) == 66.6) –var nanstr = not a number 1; –(parseInt(nanstr) == NaN) –(parseFloat(nanstr) == NaN)

String Parsing Functions (Chap 7) Split and Join Split and Join var name = Dr Sam J Smith III; var name = Dr Sam J Smith III; var words = name.split( ); var words = name.split( ); –(words[0] == Dr) –(words[4] == III) –(words.length == 5) var name2 = words.join( ); var name2 = words.join( ); –(name == name2)

String Parsing Functions (Chap 7) UPPERCASE & lowercase UPPERCASE & lowercase var name = Dr Sam J Smith III; var name = Dr Sam J Smith III; (name.toUpperCase() == DR SAM J SMITH III) (name.toUpperCase() == DR SAM J SMITH III) (name.toLowerCase() == dr sam j smith iii) (name.toLowerCase() == dr sam j smith iii) These are used to perform case- independent comparisons. These are used to perform case- independent comparisons.

Exercise 1 & 2 – Modification Write HTML to display a text field and a button. Write HTML to display a text field and a button. Pass the text field to a JavaScript function that removes things like Mr and Mrs from before the name and Jr and MD from after the name and alerts to remaining name. Pass the text field to a JavaScript function that removes things like Mr and Mrs from before the name and Jr and MD from after the name and alerts to remaining name.

Exercise 1 function strip(name) function strip(name) { var words = name.split( ); var words = name.split( ); var j = words.length-1; var j = words.length-1; var list = (Jr, Sr, III, MD); var list = (Jr, Sr, III, MD); for (var i=0; i<list.length; i++) for (var i=0; i<list.length; i++) –{ –if (list[i] == words[j]) words[j] = ; –} return words.join( ); return words.join( ); }

Exercise 1 – Important Operations Split name string into words Split name string into words Have a array of target strings Have a array of target strings Use a for loop to check all target strings Use a for loop to check all target strings Join the strings back together Join the strings back together Challenges: Challenges: –What happens with extra spaces? –Can you use one function to check for Mr and Mrs before the name and Jr and Sr after the name?

Exercise 2 function strip(name) function strip(name) { name.toUpperCase(); name.toUpperCase(); var words = name.split( ); var words = name.split( ); var list = (JR, SR, III, MD); var list = (JR, SR, III, MD); for (var i=0; i<list.length; i++) for (var i=0; i<list.length; i++) –{ –if (list[i] == words[j]) words[j] = ; –} return words.join( ); return words.join( ); }

Exercise 2 – Important Operations Use.toUpperCase() or.toLowerCase() to be case independent Use.toUpperCase() or.toLowerCase() to be case independent Find a way to ignore.s without doubling the number of entries in the list Find a way to ignore.s without doubling the number of entries in the list Challenges: Challenges: –Can you return the name with the original uppercase and lowercase characters? –Can you correctly strip Mrs. Lady Sara J Jones MD Ph.D. Esquire?