ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.

Slides:



Advertisements
Similar presentations
Java
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
Strings in Java 1. strings in java are handled by two classes String &
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
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.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
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.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
6.1 JavaScript Objects and Object- Oriented Programming (OOP)
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
Fundamental Programming Structures in Java: Strings.
Tutorial 14 Working with Forms and Regular Expressions.
 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
1.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
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.
Tutorial 14 Working with Forms and Regular Expressions.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming regular expressions.
JavaScript, Part 2 Instructor: Charles Moen CSCI/CINF 4230.
Chapter 7: Characters, Strings, and the StringBuilder.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
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.
CSC Programming I Lecture 9 September 11, 2002.
JavaScript Loops. Looping Want to be able to do things more than once Basic: for (var i=initial; while-clause; increment) { statement; }
Strings Methods in the String class Manipulating text in Java.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
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);
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
String String Builder.
Working with Forms and Regular Expressions
Primitive Types Vs. Reference Types, Strings, Enumerations
Modern Programming Tools And Techniques-I Lecture 11: String Handling
Chapter 7: Strings and Characters
Object Oriented Programming
Tonga Institute of Higher Education
15-110: Principles of Computing
Topics Basic String Operations String Slicing
JavaScript: Objects.
String Processing 1 MIS 3406 Department of MIS Fox School of Business
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
Strings in Java.
Topics Basic String Operations String Slicing
Exam Prep.
Topics Basic String Operations String Slicing
String Methods Strings have actions known as method. We will review a few of the methods associated with strings that are a part of the built in Java.
What We Want To Do User enters: Mary Smith
Presentation transcript:

ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings

ECA 225 Applied Interactive Programming2 this keyword  passes a value to a function based solely on the context of where this is used  can be used to pass entire objects, such as all values submitted through a form

ECA 225 Applied Interactive Programming3 this keyword cont...  compared to function process_form( input ){ var first = input.first_name.value; var last = input.last_name.value; } function process_form( ){ var first = document.myForm.first_name.value; var last = document.myForm.last_name.value; }

ECA 225 Applied Interactive Programming4 String( ) object  creating a String( ) object  a var which has been assigned a string has access to all String properties and methods var greeting = new String( “Hello” ); var greeting = “Hello”;

ECA 225 Applied Interactive Programming5 String( ) properties PropertyDescription lengthreturns the length of the string prototype allows a programmer to add properties to instances of the String( )object  to access a String( ) property use dot notation var greeting = “Hello”; alert( greeting.length );

ECA 225 Applied Interactive Programming6 String( ) methods MethodDescription charAt( ) returns the character at the index passed to the method concat( ) concatenates two passed strings to return a new string indexOf( ) returns the index of the first occurrence of the string passed to the method lastIndexOf( ) returns the index of the last occurrence of the string passed to the method match( ) returns an array containing the matches found based on a regular expression

ECA 225 Applied Interactive Programming7 String( ) methods cont … MethodDescription replace( ) performs a search and replace using a regular expression search( )returns the index location of a match slice( ) returns the string found between the beginning and ending index passed to the method split( )returns the string split into segments substr( ) returns the string beginning with the indexed location and number of characters to return

ECA 225 Applied Interactive Programming8 String( ) methods cont … MethodDescription substring( ) returns the string between the beginning and ending index passed to the method toLowerCase( ) converts all the character in the string to lowercase toString( )returns all passed characters as a string toUpperCase( ) converts all the character in the string to uppercase

ECA 225 Applied Interactive Programming9 String( ) methods cont …  to use a String( )method use dot notation  all methods return a value of some kind  most of the time, what’s returned is some version of the original string  use of String( ) methods do not change the value of the original string  to save what is returned, assign it to a var

ECA 225 Applied Interactive Programming10 string.toUpperCase( )  converts all the characters in the string to uppercase var greeting = “Hello”; var result = greeting.toUpperCase( ); // returns HELLO

ECA 225 Applied Interactive Programming11 string.toLowerCase( )  converts all the characters in the string to lowercase var greeting = “Hello”; var result = greeting.toLowerCase( ); // returns hello

ECA 225 Applied Interactive Programming12 string.indexOf( )  determines if one string is contained by another  index values are zero based  returns the index of the character in the larger string where the smaller string begins  if no match occurs, -1 is returns  to check for a simple match, test whether the returned value is something other than –1  optional 2 nd parameter, the starting index of the search

ECA 225 Applied Interactive Programming13 string.indexOf( ) cont … var greeting = “Hello my Baby.”; var result = greeting.indexOf(“Hello”); alert( greeting ); alert ( result );  change argument to “llo”  change argument to “ool”

ECA 225 Applied Interactive Programming14 string.charAt( )  extracts a single character at a known position  pass the method an index number as an argument  returns the character at the index number var greeting = “Hello my Baby.”; var letter = greeting.charAt( 0 ); alert ( letter );

ECA 225 Applied Interactive Programming15 string.charAt( ) cont …  print the string using  for loop  length property  charAt( ) var greeting = “Hello my Baby.”; for( i=0; i<greeting.length; i++ ){ document.write(greeting.charAt( i )) }

ECA 225 Applied Interactive Programming16 string.substring( ) cont …  extracts a contiguous string of characters  takes 2 parameters  beginning index  ending index ( not part of the substring ) var greeting = “Hello my Baby.”; var result = greeting.substring( 0,4 ); alert( result );

ECA 225 Applied Interactive Programming17 string.substr( ) cont …  extracts a contiguous string of characters  takes 2 parameters  beginning index  length of the substring var greeting = “Hello my Baby.”; var result = greeting.substr( 9,4 ); alert( result );

ECA 225 Applied Interactive Programming18 form validation  form input validation using charAt( ) function valZip( ){ var zip = document.form1.zip.value; if( zip.length != 5 ) { alert( “Invalid zip code") } for( i=0; i 9 ) { alert( “Invalid zip code") } }