An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Advertisements

Programming Logic and Design Sixth Edition
Programming with Microsoft Visual Basic 2005, Third Edition
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 10 Void Functions.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 13 Sequential Access Files.
An Introduction to Programming with C++ Fifth Edition
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Chapter 8: Manipulating Strings
An Introduction to Programming with C++ Fifth Edition Chapter 6 More on the Selection Structure.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 8 More on the Repetition Structure.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic 2008: Reloaded Fourth Edition
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Chapter 8: Manipulating Strings
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Chapter 7 Continued Arrays & Strings. Strings as Class Members Strings frequently appear as members of classes. The next example, a variation of the objpart.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 8: Simple Data Types, Namespaces, and the string Type.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Strings, StringBuilder, and Character
JavaScript Objects.
The Selection Structure
Primitive Types Vs. Reference Types, Strings, Enumerations
An Introduction to Programming with C++ Fifth Edition
CIS16 Application Development and Programming using Visual Basic.net
String Manipulation and More Controls
Microsoft Visual Basic 2005: Reloaded Second Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
Programming Logic and Design Fifth Edition, Comprehensive
An Introduction to Programming with C++ Fifth Edition
Presentation transcript:

An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation

An Introduction to Programming with C++, Fifth Edition2 Objectives Determine the number of characters contained in a string Remove characters from a string Access characters contained in a string Replace characters in a string Insert characters within a string

An Introduction to Programming with C++, Fifth Edition3 Objectives (continued) Search a string for another string Compare a portion of a string variable’s contents to another string Duplicate a character within a string variable Concatenate strings Perform string manipulation in.NET C++

An Introduction to Programming with C++, Fifth Edition4 Concept Lesson Manipulating Strings Determining the Number of Characters Contained in a String Removing Characters from a String Accessing Characters Contained in a String Replacing Characters in a String

An Introduction to Programming with C++, Fifth Edition5 Concept Lesson (continued) Inserting Characters within a String Searching a String Comparing a Portion of a String with Another String Duplicating a Character within a String Variable Concatenating Strings

An Introduction to Programming with C++, Fifth Edition6 Manipulating Strings Programs often need to manipulate string data –For example Verify that an inventory part number begins with a specific letter Determine whether the last three characters in an employee number are valid

An Introduction to Programming with C++, Fifth Edition7 Determining the Number of Characters Contained in a String Use length() to determine the number of characters in a string variable –Or use size() Syntax: string.size()

An Introduction to Programming with C++, Fifth Edition8 Determining the Number of Characters Contained in a String (continued)

An Introduction to Programming with C++, Fifth Edition9 Determining the Number of Characters Contained in a String (continued)

An Introduction to Programming with C++, Fifth Edition10 Removing Characters from a String Use erase() to remove one or more characters located anywhere in a string variable –Syntax in Figure 12-2 subscript and count arguments can be numeric literal constants or the names of numeric variables

An Introduction to Programming with C++, Fifth Edition11 Removing Characters from a String (continued)

An Introduction to Programming with C++, Fifth Edition12 Accessing Characters Contained in a String You may need to determine whether a specific letter appears as the third character in a string Or, you may need to display only the string’s first five characters Use substr() to access any number of characters contained in a string variable –“substr” stands for “substring”

An Introduction to Programming with C++, Fifth Edition13 Accessing Characters Contained in a String (continued)

An Introduction to Programming with C++, Fifth Edition14 Accessing Characters Contained in a String (continued)

An Introduction to Programming with C++, Fifth Edition15 Replacing Characters in a String Use replace() to replace a sequence of characters in a string variable with another sequence of characters –Syntax in Figure 12-4 replacementString can be a string literal constant or the name of a string variable

An Introduction to Programming with C++, Fifth Edition16 Replacing Characters in a String (continued)

An Introduction to Programming with C++, Fifth Edition17 Inserting Characters within a String insert() inserts characters within a string

An Introduction to Programming with C++, Fifth Edition18 Searching a String Use find() to search a string variable to determine if it contains a sequence of characters

An Introduction to Programming with C++, Fifth Edition19 Searching a String (continued)

An Introduction to Programming with C++, Fifth Edition20 Comparing a Portion of a String with Another String Use the comparison operators to compare strings –>, >=, <, <=, ==, and != –E.g., while (name != "DONE") To compare a portion of one string with another string, use compare()

An Introduction to Programming with C++, Fifth Edition21 Comparing a Portion of a String with Another String (continued)

An Introduction to Programming with C++, Fifth Edition22 Comparing a Portion of a String with Another String (continued)

An Introduction to Programming with C++, Fifth Edition23 Duplicating a Character within a String Variable Use assign() to duplicate a character a specified number of times

An Introduction to Programming with C++, Fifth Edition24 Duplicating a Character within a String Variable (continued)

An Introduction to Programming with C++, Fifth Edition25 Concatenating Strings Connecting (or linking) strings together is called concatenating In C++, you concatenate strings using the concatenation operator –The + sign

An Introduction to Programming with C++, Fifth Edition26 It is easier to use: hyphens.assign(5, '-'); Concatenating Strings (continued)

An Introduction to Programming with C++, Fifth Edition27 Summary String manipulation is a common programming task

An Introduction to Programming with C++, Fifth Edition28 Summary (continued)

An Introduction to Programming with C++, Fifth Edition29 Application Lesson: Using String Manipulation in a C++ Program Lab 12.1: Stop and Analyze Lab 12.2 –Program that allows two students to play a simplified version of the Hangman Game on the computer Lab 12.3 –Modify program so that it allows player 1 to enter a word of any length Lab 12.4: Desk-Check Lab Lab 12.5: Debugging Lab