STRINGS BY: DANIEL, JUSTIN, PANI.

Slides:



Advertisements
Similar presentations
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Advertisements

Java Programming Strings Chapter 7.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
Fundamental Programming Structures in Java: Strings.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
The Java String Type CSC 1401: Introduction to Programming with Java Week 7 – Lecture 1 Wanda M. Kunkle.
String Escape Sequences
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
Strings.
String Manipulation. Java String class  The String class represents character strings “Tammy Bailey”  All strings (arrays of characters) in Java programs.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Introduction to Java Java Translation Program Structure
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.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Chapter 7: Characters, Strings, and the StringBuilder.
String Processing Word processing term papers, writing memoirs, sending messages, responding to surveys, placing online orders and registering products.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Java String Methods - Codehs
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Logical Functions Excel Lesson 10.
Chapter 6 JavaScript: Introduction to Scripting
Topic Pre-processor cout To output a message.
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
String class.
Computing Fundamentals
JavaScript Objects.
Strings string: An object storing a sequence of text characters.
Multiple variables can be created in one declaration
Introduction to Scripting
Web Programming– UFCFB Lecture 19-20
Microsoft Visual Basic 2005 BASICS
Primitive Types Vs. Reference Types, Strings, Enumerations
Chapter 7: Strings and Characters
Part a: Fundamentals & Class String
Creation, Traversal, Insertion and Removal
CHAPTER THREE Sequences.
Exposure Java 2015 Pre-AP®CS Edition Chapter 12 Slides String Methods
Week 9 – Lesson 1 Arrays – Character Strings
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Microsoft Visual Basic 2005 BASICS
Chapter 2: Java Fundamentals
Wednesday 09/23/13.
Coding Concepts (Data- Types)
Basic String Operations
elementary programming
Chapter 2: Introduction to C++.
String.
Topics Basic String Operations String Slicing
String Processing 1 MIS 3406 Department of MIS Fox School of Business
An Introduction to Programming with C++ Fifth Edition
Introduction to Computer Science
Strings string: An object storing a sequence of text characters.
Java: Variables, Input and Arrays
Topics Basic String Operations String Slicing
Methods in the String class Manipulating text in Java
Topics Basic String Operations String Slicing
COMPUTING.
Pre-AP® Computer Science Quiz
Unit-2 Objects and Classes
Presentation transcript:

STRINGS BY: DANIEL, JUSTIN, PANI

WHAT ARE STRINGS? Strings are a sequence of characters, for example; “Hello World”. In java, strings have different variations and can be manipulated using different commands. Commands such as string variables, string literals, string arrays, etc.

STRING VARIABLE STRING LITERAL A string variable is a variable that contains information only with strings in it. Moreover, numbers that are contained in a string variable is recognized by the computer as a string and not an integer. You can use these variables in many ways such as storing information for an input program. For example: String name=“Mooney”; While, a string literal is a constant. A sequence of fixed characters between quotation marks. For example: Label1.setText(“Hello World”); String phonenumber=“6474206921”;

CONCATENATION It is the combination of a string literal and a string variable. Basically the adding together of strings. For example: String s1=“World” ← a string variable System.out.print(“Hello”+s1); a string literal

STRING COMMANDS Firstly, let’s declare the string variables used to demonstrate the different commands: String firstword=“HELLO”; String secondword=“hello”; 1) firstword.equals(secondword) is used to check if 2 strings are equal to one another. Example: if(firstword.equals(secondword)) { label1.setText(“The words match”); } Therefore, the text in label1 in this case will not become “The words match” as the firstword does not equal the secondword.

1[variation]) firstword 1[variation]) firstword.equalsIgnoreCase(secondword) will ignore the ‘case’(upper or lower) of the letters when checking equality. Example: if(firstword.equalsIgnoreCase(secondword)) { label1.setText(“The words match”); } Therefore, the text in label1 in this case will become “The words match”. 2) firstword.length() is used to determine the length or number of characters in the string. Example: int wordlength=0; wordlength=firstword.length(); Therefore, wordlength in this case will equal to 5 as there are 5 characters stored in the string variable called firstword.

3) firstword.charAt(N) is used to isolate a particular character within a string based on the numeric position of the character. Example: label1.setText(“”+secondword.charAt(0)+secondword.charAt(2)); Therefore, the text in label1 in this case will become “hl”. 4) firstword.substring(N,M) is used to isolate and separate a small group of neighbouring characters within a larger string. N is the start position of the group of letters you want to remove and M is the finish position +1. Example: label1.setText(firstword.substring(1,4)); Therefore, the text in label1 in this case will become “ELL”.

5) firstword.toUpperCase() is used to convert a string of characters to all any specified type of letters (“UpperCase” could be replaced with “LowerCase” or “TitleCase”). Example: label1.setText(secondword.toUpperCase()); Therefore, the text in label1 in this case will become “HELLO”. 6) s1.indexOf(s2) returns an integer that is the starting position of a substring (s2) if it occurs (or can be found) within s1. The returned value is the starting position of that substring (s2). If s2 is not within s1 the returned value is -1. Example: String s1=“Hello World”; String s2=“lo”; int location=0; location=s1.indexOf(s2); System.out.print(location); Therefore, location will equal to 3 and will display the number 3.

String name = “John Laban”; STRING COMMANDS CHART String name = “John Laban”; name.equals(“Justin Smith”); false name.compareToIgnoreCase(“john laban”); true name.indexOf(“an”); 7 name.startsWith(“J”); name.length(); 10 name.toLowerCase(); “john laban” name.toUpperCase(); “JOHN LABAN” name.substring(3,7); “n La” name. replaceAll(“a”, ”o”); “John Lobon”