1 STRINGS String data type Basic operations on strings String functions String procedures.

Slides:



Advertisements
Similar presentations
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Advertisements

 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
JavaScript, Third Edition
Introduction. In today’s session… What is programming? Why should I learn programming? Course Outline Introduction to Programming Language Introduction.
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
Chapter 5 new The Do…Loop Statement
EPSII 59:006 Spring Introduction Fundamentals of Strings and Characters Character Handling Library String Conversion Functions Standard Input/Output.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Lecture 13 Midterm overview When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it: this is.
Input, Output, and Processing
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Chapter 2 – Continued Basic Elements of Java. Chapter Objectives Type Conversion String Class Commonly Used String Methods Parsing Numeric Strings Commonly.
Chapter 2: Java Fundamentals Type conversion,String.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Pascal Programming Today Chapter 11 1 Chapter 11.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
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.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Chapter 9 Strings J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University of Technology.
Characters and Strings
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
Strings … operators Up to now, strings were limited to input and output and rarely used as a variable. A string is a sequence of characters or a sequence.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
Definition of the Programming Language CPRL
Topics Designing a Program Input, Processing, and Output
String Concepts In general, a string is a series of characters treated as a unit. Computer science has long recognized the importance of strings, but it.
JavaScript Objects.
Chapter 2: Basic Elements of Java
Strings Dr. Soha S. Zaghloul updated by Rasha ALEidan
Chapter 8 Character Arrays and Strings
Topics discussed in this section:
functions: argument, return value
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Presentation transcript:

1 STRINGS String data type Basic operations on strings String functions String procedures

2 Definition of Strings character data –e.g., ‘A’, ‘B’, ‘C’, ‘x’, ‘y’, ‘z’, ‘!’, ‘*’, etc. sequences of characters –e.g., ‘computer programming’

3 String Data Type string constant –a sequence of characters enclosed in single quotation marks - ‘ ’ –quotation marks themselves are not –e.g., ‘John’ ‘s computer’ string variable –a predefined type identifier in Pascal –e.g., var Student : string[30]

4 Basic Operations on Strings assignment input/output accessing individual characters of a string comparison initializing a string variable

5 1. Assignment assigned value length < declared length –no problem assigned value length > declared length –the value is truncated to the declared length –only the leftmost characters are retained Exercise - what is the output of: –writeln(Name, class);

6 2. Input/output Input –use readln statement –input string value : no need to enclosed in ‘ ’ except this case, ‘bbbABC Company’ Output –use write, or writeln statements leading spaces

7 3. Accessing individual characters a string can be treated as a special array of characters example: var Name : string;.. Name := ‘Jacky’; writeln(Name[2]); ‘J’ ‘a’ ‘c’ ‘k’ ‘y’ Name[1] Name[2] Name[3] Name[4] Name[5]

8 4. Comparison strings are compared with, =, = and <> two characters are compared with one another according to their ASCII value two strings are compared with one another character by character

9 5. Initializing a string variable an uninitialized string may contain unpredictable value initialize a string variable with a null string: Sentence := ‘’ no space in between

10 String Functions length concat copy ord chr

11 length length( ) –returns the length of a –i.e., the number of characters in the string

12 concat concatenation –the process of joining strings together to form longer string 2 methods: –concat(,,..., ) –using concatenation operator, +

13 copy copy(,, ) –returns a substring with the special from the, beginning at position –used to cut off part of a string

14 ord & chr ord( ) –returns the ASCII value of a chr( ) –returns the ASCII character associated with that

15 String Procedures some useful procedures are pre-declared and can be used by the program writers at any time they want –e.g., read, readln, write and writeln those concerning string are: –val –str

16 val val(,, ) –converts to its numeric equivalent conversion –successful: - numeric value - the value 0 –failure: - set to 0 - the position of the 1st invalid character declaration error code

17 str str(, ) –converts a numeric value,, to its string representation –assigns this string value to field descriptors can be included to specify the string format –str( : :, ) width no. of decimal place

18 The End