Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic 2010 2 nd Edition.

Slides:



Advertisements
Similar presentations
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
Advertisements

Chapter 11: Classes and Objects
Programming with Microsoft Visual Basic 2005, Third Edition
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
Chapter 8: Manipulating Strings
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
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
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Programming with Microsoft Visual Basic 2008 Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Fundamentals of Python: First Programs
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 8: Manipulating Strings
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Programming with Microsoft Visual Basic th Edition
1.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
Programming with Microsoft Visual Basic th Edition
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 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Decisions with Select Case and Strings Chapter 4 Part 2.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
8 1 String Manipulation CGI/Perl Programming By Diane Zak.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 11: Testing, Testing…1, 2, 3
Microsoft Visual Basic 2008: Reloaded Third Edition
Computer Programming ||
Multiple Classes and Inheritance
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
Presentation transcript:

Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition

Objectives Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 2 After studying Chapter 23, you should be able to: Determine the number of characters in a string Remove spaces from the beginning and end of a string Replace characters in a string Insert characters in a string Search a string

Objectives (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 3 Access characters in a string Remove characters located anywhere in a string Compare strings using pattern-matching

Working with Strings Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 4 Many times: An application will need to manipulate (process) string data in some way The first string manipulation technique in this chapter Shows you how to determine the number of characters in a string

How Many Characters Are There? Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 5 If an application expects the user to enter a seven-digit phone number: Application’s code should verify that the user entered the required number of characters Number of characters contained in a string Stored in the string’s Length property Value stored in the property is an integer

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 6 Figure 23-1 Syntax and examples of the Length property

Get Rid of Those Spaces Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 7 Trim method Used to remove (trim) any spaces from both the beginning and end of a string Does not remove any characters from the original string Returns a string that excludes any leading or trailing spaces

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 8 Figure 23-2 Syntax and examples of the Trim method

The Product ID Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 9 Displays (in a label control): A listing of the product IDs entered by the user Each product ID must contain exactly five characters

Let’s Make a Substitution Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 10 Replace method Used to replace a sequence of characters in a string with another sequence of characters Figure 23-4 oldValue The sequence of characters that you want to replace in the string newValue The replacement characters

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 11 Figure 23-4 Syntax and examples of the Replace method

I Need To Fit This in Somewhere Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 12 Insert method Used to insert characters Examples Insert an employee’s middle initial within his or her name Insert parentheses around the area code in a phone number

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 13 Figure 23-5 Syntax and examples of the Insert method

The Phone Numbers Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 14 Saves (in a sequential access file): The phone numbers entered by the user Each phone number is entered using: 12 characters in the following format: Before writing a phone number to the file: The application removes the hyphens and then verifies that the phone number contains 10 characters Figures 23-7 and 23-9 Show code and resulting display

The Phone Numbers Application (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 15 Figure 23-7 Statements needed to insert the two hyphens

The Phone Numbers Application (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 16 Figure 23-9 Statements needed to insert the two hyphens

Where Does It Begin? Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 17 IndexOf method Used to search a string to determine whether it contains a specific sequence of characters Examples Determining whether the area code “(312)” appears in a phone number Determining whether “Elm Street” appears in an address

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 18 Figure Syntax and examples of the IndexOf method

I Just Want a Part of It Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 19 Substring method Used to access any number of characters contained in a string Figure startIndex The index of the first character you want to access in the string numCharsToAccess argument Specifies the number of characters you want to access

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 20 Figure Syntax and examples of the Substring method

The Rearrange Name Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 21 User interface Provides a text box for entering a person’s first name followed by a space and the person’s last name Application Rearranges name so that the last name comes first, followed by a comma, a space, and the first name Figure Shows code to display rearranged name

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 22 Figure btnRearrange control’s Click event procedure

Throw Away Those Characters Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 23 Remove method Removes specified number of characters Characters may be located anywhere in a string startIndex argument Index of first character you want removed from the string numCharsToRemove argument Specifies number of characters you want removed

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 24 Figure Syntax and examples of the Remove method

The Last Name Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 25 Interface provides a text box User enters a person’s first name, a space, and the last name Application displays only the person’s last name

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 26 Figure btnDisplay control’s Click event procedure

I Like This Operator Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition 27 Like operator Allows you to use pattern-matching characters to determine whether one string is equal to another Figure In the syntax, both string and pattern must be String expressions However, pattern can contain one or more of the pattern-matching characters listed in the figure

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 28 Figure Syntax and examples of the Like operator (continues)

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 29 Figure Syntax and examples of the Like operator (continues)

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 30 Figure Syntax and examples of the Like operator (cont’d.)

Modifying the Product ID Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 31 Ensure that the five characters in the product ID are three letters followed by two numbers

Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 32 Figure Click event procedure for the btnAdd control

Summary Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 33 String’s Length property Stores an integer that represents the number of characters contained in the string Visual Basic Provides methods that allow you to manipulate strings First character in a string has an index of 0