Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.

Slides:



Advertisements
Similar presentations
1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
Advertisements

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.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
Introduction to Objects and Input/Output
Chapter 7: The String class We’ll go through some of this quickly!
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
1 String Buffer & String Tokenizer Overview l Overview of String Buffer class and Methods l Overview of String Tokenizer class and methods l Preview: Notions.
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
COMP 14 Introduction to Programming Mr. Joshua Stough February 2, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
String Tokenization What is String Tokenization?
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 29, 2005.
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
StringBuffer class  Alternative to String class  Can be used wherever a string is used  More flexible than String  Has three constructors and more.
1 StringTokenizer and StringBuffer classes Overview l StringTokenizer class l Some StringTokenizer methods l StringTokenizer examples l StringBuffer class.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
Strings Edward J. Biebel. Strings Strings are fundamental part of all computing languages. At the basic level, they are just a data structure that can.
1 Infinite Loops  The body of a while loop eventually must make the condition false  If not, it is an infinite loop, which will execute until the user.
Computer Programming 2 Lecture 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
Computer Programming 2 Lecture 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
Regular Expressions.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
1 StringTokenization Overview l StringTokenizer class l Some StringTokenizer methods l StringTokenizer examples.
Objectives ► Become familiar with the class String ► ► Learn how to use input and output dialog boxes in a program ► ► Learn how to tokenize the input.
Strings Chapter 7 CSCI CSCI 1302 – Strings2 String Comparisons Compare string contents with the equals(String s) method not == String s0 = “ Java”;
Tokenizers 29-Nov-15. Tokens A tokenizer is a program that extracts tokens from an input stream A token is a “word” or a significant punctuation mark.
String Handling StringBuffer class character class StringTokenizer class.
Strings Chapter 7 CSCI CSCI 1302 – Strings2 Outline Introduction The String class –Constructing a String –Immutable and Canonical Strings –String.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
1 CHAPTER 3 StringTokenizer. 2 StringTokenizer CLASS There are BufferedReader methods to read a line (i.e. a record) and a character, but not just a single.
Files and Streams CS /02/05 L7: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
19-Dec-15 Tokenizers. Tokens A tokenizer is a program that extracts tokens from an input stream A token has two parts: Its value—this is just the characters.
Computer Programming 2 Lecture 10: File streaming (1) Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE.
Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Presented By: Mahmoud Rafeek Alfarra
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
MSIS 655 Advanced Business Applications Programming
Part a: Fundamentals & Class String
Introduction To Programming Information Technology , 1’st Semester
Introduction To Programming Information Technology , 1’st Semester
Lecture 07 String Jaeki Song.
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
Tokenizers 25-Feb-19.
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
Tokenizers 26-Apr-19.
Tokenizers 3-May-19.
Chapter 7 Strings Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. Use the String class to process fixed.
Presented By: Mahmoud Rafeek Alfarra
Presentation transcript:

Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE

و من يتقِ الله... ألا تكفيك هذه ؟ ! ( إِنَّ اللَّهَ مَعَ الَّذِينَ اتَّقَوْا وَالَّذِينَ هُمْ مُحْسِنُونَ ) ( النحل :128) Mahmoud Rafeek Alfarra 2 Downloaded from شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي

Out Lines Mahmoud Rafeek Alfarra Downloaded from Downloaded from 3 Class StringTokenizer  Introduction  Constructors  Count Tokens  Print Tokens  Token Processing

Class StringTokenizer: Introduction Mahmoud Rafeek Alfarra Downloaded from Downloaded from 4 When you read a sentence, your mind breaks the sentence into tokens individual words and punctuation marks, each of which conveys meaning to you. Tokens are separated from one another by delimiters, typically whitespace characters such as space, tab, newline and carriage return

Class StringTokenizer: Constructors Mahmoud Rafeek Alfarra Downloaded from Downloaded from 5 StringTokenizer(String str) String x = “Mahmoud Rafeek Alfarra” StringTokenizer tokens = new StringTokenizer( x ); String x = “Mahmoud Rafeek Alfarra” StringTokenizer tokens = new StringTokenizer( x );

Class StringTokenizer: Constructors Mahmoud Rafeek Alfarra Downloaded from Downloaded from 6 StringTokenizer(String str, String delim) String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/"); String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/");

Class StringTokenizer: Constructors Mahmoud Rafeek Alfarra Downloaded from Downloaded from 7 StringTokenizer(String str, String delim, boolean returnDelims) str The input String delimiters returnDelimiters Returns delimiters as tokens or skip them String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/“, false); String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/“, false);

Class StringTokenizer: CountToken Mahmoud Rafeek Alfarra Downloaded from Downloaded from 8 StringTokenizer has a countTokens() method which Calculates the reminder number of tokens in the string. String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/"); int a = tokens.countToken(); // return 3 String x = "2005/12/15“ StringTokenizer tokens = new StringTokenizer(x, "/"); int a = tokens.countToken(); // return 3

Class StringTokenizer: PrintTokens Mahmoud Rafeek Alfarra Downloaded from Downloaded from 9 StringTokenizer has a hasMoreElements() and hasMoreTokens() methods which Test if there are more tokens available from this tokenizer's string. StringTokenizer has a nextElement() and nextToken() methods which returns the next token from this string tokenizer.

Class StringTokenizer: PrintTokens Mahmoud Rafeek Alfarra Downloaded from Downloaded from 10 String x = "I love islam So Much“; StringTokenizer st= new StringTokenizer(x); while (st.hasMoreElements()) { System.out.println("token = " + st.nextToken());

Class StringTokenizer: Token Processing Mahmoud Rafeek Alfarra Downloaded from Downloaded from 11 Using the methods of StringClass as toUpperCase toLowercase comparTo … we can process the tokens and store it in data structures

Example Mahmoud Rafeek Alfarra Downloaded from Downloaded from 12 import java.util.*; public class tokenPRoject { public static void main(String[] args) { String x = "i love islam so much"; StringTokenizer a = new StringTokenizer (x); while (a.hasMoreElements()){ String f = a.nextToken(); System.out.println(f.toUpperCase()); System.out.println(a.countTokens()); } System.out.println("=================="); String [] result = x.split("\\s"); for(int i = 0; i<result.length; i++ ) System.out.println(result[i].toUpperCase( )); } }

Next Lecture … Mahmoud Rafeek Alfarra Downloaded from Downloaded from 13 Class StringBuffer