Chapter 8: Manipulating Strings

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic 2008 Fourth Edition
Advertisements

Programming with Microsoft Visual Basic th Edition
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Chapter 11: Classes and Objects
Chapter 7: Sub and Function Procedures
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
Chapter 9: Sequential Access Files and Printing
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 7: Sub and Function Procedures
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Creating Menu. Objectives Create a menu system for a form –Create a menu –Create a menu titles –Create a menu items –Create a submenu –Modify menu –Edit.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
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 Office 2007 Access 2007 Chapter 9 Administering a Database System.
Visual Basic Chapter 1 Mr. Wangler.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 12: How Long Can This Go On?
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Chapter One An Introduction to Visual Basic 2010 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.
Chapter 6: The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 8: Manipulating Strings
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Microsoft Visual Basic 2005 BASICS Lesson 1 A First Look at Microsoft Visual Basic.
1.
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.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
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.
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.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Menu & Clipboard Menu Cut / Copy / Paste. Menus Created in the Menu Editor Can contain menu titles, menu items, separator bars, submenu titles, and submenu.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Microsoft Visual Basic 2008: Reloaded Third 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
CIS16 Application Development and Programming using Visual Basic.net
Presentation transcript:

Chapter 8: Manipulating Strings Programming with Microsoft Visual Basic .NET, Second Edition

String Manipulation Lesson A Objectives Determine the number of characters contained in a string Remove characters from a string Determine whether a string begins or ends with one or more specific characters Programming with Microsoft Visual Basic .NET, Second Edition

String Manipulation Lesson A Objectives (continued) Access characters from the beginning, middle, and end of a string Replace one or more characters in a string Insert characters within a string Search a string for one or more characters Programming with Microsoft Visual Basic .NET, Second Edition

Manipulating Strings in Visual Basic .NET Many times, an application needs to manipulate (process) string data For example, an application might need to: Verify that an inventory part number begins with a specific letter Determine whether the last three characters in an employee number are valid Programming with Microsoft Visual Basic .NET, Second Edition

Determining the Number of Characters Contained in a String In many applications, it is necessary to determine the number of characters contained in a string Use a string’s Length property to determine the number of characters contained in the string Syntax of the Length property: string.Length Programming with Microsoft Visual Basic .NET, Second Edition

Removing Characters from a String TrimStart method Remove one or more characters from the beginning of a string Syntax: string.TrimStart([trimChars]) TrimEnd method Remove one or more characters from the end of a string Syntax: string.TrimEnd([trimChars]) Programming with Microsoft Visual Basic .NET, Second Edition

Removing Characters from a String (continued) Trim method Remove one or more characters from both the beginning and end of a string Syntax: string.Trim([trimChars]) Programming with Microsoft Visual Basic .NET, Second Edition

Removing Characters from a String (continued) string.Trim Removes leading and trailing spaces string.Trim(char) Removes leading and trailing char string.TrimStart Removes leading spaces string.TrimStart(char) Removes leading char string.TrimEnd Removes trailing spaces string.TrimEnd(char) Removes trailing char Programming with Microsoft Visual Basic .NET, Second Edition

The Remove Method Use the Remove method to remove one or more characters located anywhere in a string The Remove method returns a string with the appropriate characters removed Syntax: string.Remove(startIndex, count) Programming with Microsoft Visual Basic .NET, Second Edition

Determining Whether a String Begins or Ends with a Specific Sequence of Characters StartsWith method Determine whether a specific sequence of characters occurs at the beginning of a string Syntax: string.StartsWith(subString) EndsWith method Determine whether a specific sequence of characters occurs at the end of a string Syntax: string.EndsWith(subString) Programming with Microsoft Visual Basic .NET, Second Edition

Accessing Characters Contained in a String Use the Substring method to access any number of characters in a string Syntax: string.Substring(startIndex[, count]) startIndex: the index of the first character you want to access in the string count (optional): specifies the number of characters you want to access Programming with Microsoft Visual Basic .NET, Second Edition

Replacing Characters in a String Use Replace to replace a sequence of characters in a string with another sequence of characters For example: Replace area code “800” with area code “877” in a phone number Replace the dashes in a Social Security number with the empty string Programming with Microsoft Visual Basic .NET, Second Edition

Replacing Characters in a String (continued) Syntax: string.Replace(oldValue, newValue) oldValue is the sequence of characters that you want to replace in the string newValue is the replacement characters Programming with Microsoft Visual Basic .NET, Second Edition

The Mid Statement Use the Mid statement to replace a specified number of characters in a string with characters from another string Syntax: Mid(targetString, start [, count]) = replacementString targetString: the string in which you want characters replaced Programming with Microsoft Visual Basic .NET, Second Edition

The Mid Statement (continued) replacementString: contains the replacement characters start: the character position of the first character you want replaced in the targetString count: the number of characters to replace in the targetString Programming with Microsoft Visual Basic .NET, Second Edition

Inserting Characters at the Beginning and End of a String Use the PadLeft and PadRight methods to pad a string with a character until the string is a specified length PadLeft method pads the string on the left Inserts the padded characters at the beginning of the string and right-aligns the characters in the string Syntax: string.PadLeft(length[, character]) Programming with Microsoft Visual Basic .NET, Second Edition

Inserting Characters at the Beginning and End of a String (continued) PadRight method pads the string on the right Inserts the padded characters at the end of the string and left-aligns the characters in the string Syntax: string.PadRight(length[, character]) Programming with Microsoft Visual Basic .NET, Second Edition

Inserting Characters within a String Use the Insert method to insert characters within a string For example: insert an employee’s middle initial within his or her name Syntax: string.Insert(startIndex, value) startIndex specifies where in the string you want the value inserted Programming with Microsoft Visual Basic .NET, Second Edition

Searching a String Use the IndexOf method to search a string to determine whether it contains a specific sequence of characters Syntax: string.IndexOf(value[, startIndex]) value: the sequence of characters for which you are searching in the string startIndex: the index of the character at which the search should begin Programming with Microsoft Visual Basic .NET, Second Edition

Searching a String (continued) For example: Determine if the area code “312” appears in a phone number Determine if the street name “Elm Street” appears in an address Programming with Microsoft Visual Basic .NET, Second Edition

Searching a String (continued) Figure 8-13: String manipulation techniques Programming with Microsoft Visual Basic .NET, Second Edition

Searching a String (continued) Figure 8-13: String manipulation techniques (continued) Programming with Microsoft Visual Basic .NET, Second Edition

Using a Main Menu Control Lesson B Objectives Add a main menu control to a form Add menu elements to a main menu control Assign access keys and shortcut keys to menu elements Code a menu item’s Click event procedure Programming with Microsoft Visual Basic .NET, Second Edition

Completing the Hangman Game Application’s User Interface You will create a simplified version of the Hangman game for Mr. Mitchell, who teaches second grade at Hinsbrook School In this lesson, you will: Complete the application’s user interface Begin coding the application Programming with Microsoft Visual Basic .NET, Second Edition

Completing the Hangman Game Application’s User Interface (continued) Figure 8-14: Partially completed interface for the Hangman Game application Programming with Microsoft Visual Basic .NET, Second Edition

Adding a Main Menu Control to a Form Use a main menu control to include one or more menus in an application Each menu contains a menu title, which appears on the menu bar at the top of a Windows form When you click a menu title, its corresponding menu opens and displays a list of options, called menu items Programming with Microsoft Visual Basic .NET, Second Edition

Adding a Main Menu Control to a Form (continued) The menu items can be commands, separator bars, or submenu titles Clicking a command on a menu executes the command Clicking a submenu title opens an additional menu of options Programming with Microsoft Visual Basic .NET, Second Edition

Adding a Main Menu Control to a Form (continued) Figure 8-15: Location of menu elements Programming with Microsoft Visual Basic .NET, Second Edition

Adding a Main Menu Control to a Form (continued) Each option on a submenu is referred to as a submenu item The purpose of a separator bar is to visually group together the related items on a menu or submenu Each menu element is considered an object and has a set of properties associated with it The most commonly used properties for a menu element are the Name and Text properties Programming with Microsoft Visual Basic .NET, Second Edition

Assigning Shortcut Keys Appear to the right of a menu item Allow you to select an item without opening the menu You should assign shortcut keys only to commonly used menu items Programming with Microsoft Visual Basic .NET, Second Edition

Assigning Shortcut Keys (continued) Figure 8-19: Shortcut key displayed on the File menu Programming with Microsoft Visual Basic .NET, Second Edition

Coding the Click Event Procedure for the Exit Menu Item When the user clicks the Exit item on the File menu, the item’s Click event procedure should end the Hangman Game application Programming with Microsoft Visual Basic .NET, Second Edition

Completing the Hangman Game Application Lesson C Objectives Include the Substring method in a procedure Include the Mid statement in a procedure Include the IndexOf method in a procedure Programming with Microsoft Visual Basic .NET, Second Edition

The Hangman Game Application An application that two students can use to play a simplified version of the Hangman game on the computer The application should allow one of the students to enter a five-letter word, and then allow the other student to guess the word, letter by letter The game is over when the second student either guesses all of the letters in the word or makes 10 incorrect guesses, whichever comes first Programming with Microsoft Visual Basic .NET, Second Edition

The Hangman Game Application (continued) Figure 8-22: Hangman Game application’s user interface Programming with Microsoft Visual Basic .NET, Second Edition

Coding the Click Event Procedure for the uiFileNewMenuItem Each time the user wants to begin a new Hangman game, he or she will need to: Click File on the application’s menu bar Click New Game Programming with Microsoft Visual Basic .NET, Second Edition

Coding the Click Event Procedure for the uiFileNewMenuItem (continued) Figure 8-24: Pseudocode for the uiFileNewMenuItem’s Click event procedure Programming with Microsoft Visual Basic .NET, Second Edition

Coding the Click Event Procedure for the uiFileNewMenuItem (continued) Figure 8-24: Pseudocode for the uiFileNewMenuItem’s Click event procedure (continued) Programming with Microsoft Visual Basic .NET, Second Edition

Summary To determine the number of characters contained in a string, use the Length property in the following syntax: string.Length To remove one or more characters from anywhere in a string, use the Remove method Use the StartsWith method to determine whether a string begins with a specific sequence of characters Programming with Microsoft Visual Basic .NET, Second Edition

Summary (continued) Use the EndsWith method to determine whether a string ends with a specific sequence of characters To access one or more characters contained in a string, use the Substring method To insert characters within a string, use the Insert method Programming with Microsoft Visual Basic .NET, Second Edition

Summary (continued) To search a string to determine whether it contains a specific sequence of characters, use the IndexOf method To add a main menu control to a form, use the MainMenu tool in the toolbox To assign a shortcut key to a menu item, set the menu item’s Shortcut property To replace a character in a string with another character, use the Mid statement Programming with Microsoft Visual Basic .NET, Second Edition