10 – Java Script (3) Informatics Department Parahyangan Catholic University.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Intro to Javascript CS Client Side Scripting CS380 2.
Stacks, Queues, and Linked Lists
Stack & Queues COP 3502.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Java Programming Strings Chapter 7.
Java Strings in 10 minutes
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Regular Expression ASCII Converting. Regular Expression Regular Expression is a tool to check if a string matches some rules. It is a very complicated.
Practical Extraction & Report Language Picture taken from
25-Jun-15 JavaScript Language Fundamentals II. 2 Exception handling, I Exception handling in JavaScript is almost the same as in Java throw expression.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
CSE 341 Lecture 24 JavaScript arrays and objects slides created by Marty Stepp
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
Regular Expression A regular expression is a template that either matches or doesn’t match a given string.
REGULAR EXPRESSIONS CHAPTER 14. REGULAR EXPRESSIONS A coded pattern used to search for matching patterns in text strings Commonly used for data validation.
Programming for Linguists An Introduction to Python 24/11/2011.
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Hossain Shahriar Announcement and reminder! Tentative date for final exam need to be fixed! Topics to be covered in this lecture(s)
CIS 218 Advanced UNIX1 Advanced UNIX CIS 218 Advanced UNIX Regular Expressions.
Copyright ©2005  Department of Computer & Information Science JavaScript Regular Expressions.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming regular expressions.
12. Regular Expressions. 2 Motto: I don't play accurately-any one can play accurately- but I play with wonderful expression. As far as the piano is concerned,
CS346 Regular Expressions1 Pattern Matching Regular Expression.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
Java Script Pattern Matching Using Regular Expressions.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
INT222 – Internet Fundamentals Week 11: RegExp Object and HTML5 Form Validation 1.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
Strings Methods in the String class Manipulating text in Java.
17-Feb-16 String and StringBuilder Part I: String.
Chapter 4 © 2009 by Addison Wesley Longman, Inc Pattern Matching - JavaScript provides two ways to do pattern matching: 1. Using RegExp objects.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
JavaScript and Ajax (JavaScript Arrays) Week 5 Web site:
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
Review: A Structural View program modules -> main program -> functions -> libraries statements -> simple statements -> compound statements expressions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
The Methods and What You Need to Know for the AP Exam
Java Script Date Object
String and Lists Dr. José M. Reyes Álamo.
JavaScript.
Applied Component I Unit II Introduction of java-script
Working with Collections of Data
SEEM4570 Tutorial 05: JavaScript as OOP
Perl Variables: Array Web Programming.
CIT 383: Administrative Scripting
Functions, Regular expressions and Events
String and Lists Dr. José M. Reyes Álamo.
2017, Fall Pusan National University Ki-Joune Li
CIT 383: Administrative Scripting
Javascript data structures
Introduction to Computer Science
Presentation transcript:

10 – Java Script (3) Informatics Department Parahyangan Catholic University

 Shifting Elements  works like popping an element, but instead of removing the last element, shift() method removes the first element and shifts all other elements forward.  works like dequeue in Queue data structure  Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; var removed = fruits.shift(); //fruits = ["Orange", "Apple", "Mango"] //removed = “Banana”

 Unshifting Elements  The unshift() method adds a new element at the beginning of an array and shifts the old elements backward  Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.unshift("Lemon"); //fruits = ["Lemon", "Banana", "Orange", "Apple", "Mango"]

 Deleting Elements  Changes an element to undefined  This leaves a “hole” in an array  Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; delete fruits[1]; //fruits = ["Banana", undefined, "Apple", "Mango"]

 Splicing an Array  The splice() method can be used to add new items or remove some items to/from an array  Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.splice(2, 1, "Lemon", "Kiwi"); //fruits = ["Banana", "Orange", "Lemon", "Kiwi", "Mango"] where to splice how many elements should be removed new elements to be inserted

 Slicing an Array  The slice() method slices out a piece of an array into a new array  Example: var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(1, 3); //citrus = ["Orange", "Lemon“] starting indexending index (not included in the result)

 Searching in an Array  The indexOf() method searches the array for an element and return its position (first to be found)  The lastIndexOf() method searches the array for and element, starting at the end, and returns its position  Example: var foo = ["H", "E", "L", "L", "O"]; var firstL = foo.indexOf("L");//2 var lastL = foo.lastIndexOf("L");//3

 A regular expression is a sequence of characters that forms a search pattern.  The search pattern can be used for text search and text replace operations.

 Syntax: /pattern/modifiers;  Example:  w3school is a pattern (to be used in search)  i is a modifier (modifies the search to be case-insensitive) var patt = /w3schools/i;

 In Java Script, RE usually used for search() and replace() string methods  Example: var str = "Visit W3Schools"; var n = str.search(/w3schools/i); //n = 6 var str = "Visit W3Schools!"; var n = str.search("W3Schools"); //n = 6 var str = "Visit W3Schools!"; var n = str.search(“w3schools"); //n = -1

 Example: var str = "Visit Microsoft!"; var res = str.replace(/microsoft/i, "W3Schools"); //res = "Visit W3Schools!" var str = "Visit Microsoft!"; var res = str.replace("Microsoft", "W3Schools"); //res = "Visit W3Schools!" var str = "Visit Microsoft!"; var res = str.replace(”microsoft", "W3Schools"); //res = "Visit Microsoft!"

 Modifiers  i perform case-insensitive matching  g perform a global match (find all the matches rather than stopping after the first match)  m perform multiline matching (find first occurrences in every line)

 Patterns: Brackets are used to find a range of characters  [abc] find any characters which is a, b or c  [^abc] find any characters which is not a, not b, and not c  [a-z] find any characters between a and z (inclusive)  [^a-z] find any characters which is not a, b,..., z (inclusive)

 Quantifiers:  n+ matches any string that contains at least one n  n* matches any string that contains zero or more occurrences of n  n? matches any string that contains zero or one occurrences of n

 The test() method is a RE method. It searches a string for a pattern, and returns true or false, depending on the result.  Example: var patt = /free/; patt.test("The best things in life are free!"); //returns true since the string has “free” in it var patt = /frees/; patt.test("The best things in life are free!"); //returns false since the string doesn’t has “frees” in it

 Example: var patt = /frees*/; patt.test("The best things in life are free!"); //returns true since the string has “free” in it. Note that s* means zero s is permitable var patt = /frees+/; patt.test("The best things in life are free!"); //returns false since the string has “frees” in it var patt = /fre?!/; patt.test("The best things in life are free!"); //returns false since e?! means zero or one e then followed by a “!”. In this string there is 2 “e”s