Tonga Institute of Higher Education

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.
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.
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 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
Java Strings in 10 minutes
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
Strings Reading for this Lecture, L&L, 3.2. Strings String is basically just a collection of characters. Thus, the string “Martyn” could be thought of.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
1 Strings and String Operations  What is a Strings?  Internal Representation of Strings  Getting Substrings from a String  Concatenating Strings 
1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
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.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
CSC Programming I Lecture 9 September 11, 2002.
CSI 3125, Preliminaries, page 1 String. CSI 3125, Preliminaries, page 2 String Class Java provides the String class to create and manipulate strings.
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.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
Strings Methods in the String class Manipulating text in Java.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
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.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Chapter 8 String Manipulation
The Methods and What You Need to Know for the AP Exam
Strings A String is a sequence of letters
Introduction to programming in java
Java String Methods - Codehs
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Math and String Examples
String class.
EKT 472: Object Oriented Programming
String Handling in JAVA
Modern Programming Tools And Techniques-I Lecture 11: String Handling
F4105 JAVA PROGRAMMING F4105 Java Programming
Chapter 7: Strings and Characters
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
Advanced String handling
Part a: Fundamentals & Class String
Microsoft Visual Basic 2005: Reloaded Second Edition
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
String methods 26-Apr-19.
String Methods.
Strings in Java.
Introduction to Computer Science
Exam Prep.
Switch, Strings, and ArrayLists in Java
Methods in the String class Manipulating text in Java
Pre-AP® Computer Science Quiz
Unit-2 Objects and Classes
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:

Tonga Institute of Higher Education String Manipulation Tonga Institute of Higher Education

Introduction We know how to combine strings together and why this is useful Why is it useful to break strings apart? Extraction of data Example: My birthday is “07-07-76”. How can we determine the year from this string? How do we break strings apart?

String.charAt Method - 1 A char datatype is different from a String datatype A char is only 1 character (letter) ‘a’ ‘5’ A String contains many characters “Hello” “Sione” You can get the char for each location in a string using the charAt method

String.charAt Method - 2 A String is like an array of characters 1 2 3 4 Index A String is like an array of characters Each cell of this array contains 1 character To get a character located at an index, we can use the charAt method Prints H

String.subString Method - 1 l o 1 2 3 4 Index Use the subString method to get a smaller string from a larger string Example: To get “Sione” from “Sione Tupou”

String.subString Method - 2 l o 1 2 3 4 Index 1 2 The first method has only 1 parameter It returns everything from that index to the end of the string Prints “lo”

String.subString Method - 3 l o 1 2 3 4 Index 1 2 The second method has only 2 parameter It returns everything from the first index up to the second index Prints “ll”

String.indexOf Method - 1 l o 1 2 3 4 Index Use the indexOf method to get the index number of a char or a string Example: To find that the index of the first ‘l’ char is 2 -1 is returned if the char or string doesn’t exist 1 2 3 4

String.indexOf Method - 2 l o 1 2 3 4 Index 1 2 3 4 Returns 1 Find index of characters Returns -1

String.indexOf Method - 3 l o 1 2 3 4 Index 1 2 3 4 Returns 2 Find index of Strings Returns 3 Start searching from this index

String.length Method To get the number of characters in a string, use the length method Returns 5

More Methods Available trim – Removes whitespace before and after string toUpperCase – Changes all characters to upper case toLowerCase - Changes all characters to lower case Check the API documentation for a complete list of the methods available