Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.

Slides:



Advertisements
Similar presentations
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Advertisements

Programming with Microsoft Visual Basic th Edition
Chapter 7: Sub and Function Procedures
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
String Variables Visual Basic for Applications 4.
Chapter 8: Manipulating Strings
Using the Visual Basic Editor Visual Basic for Applications 1.
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.
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
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
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.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
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.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Chapter 6: The Repetition Structure
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Tutorial 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
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.
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.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
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.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
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.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Java Programming: Guided Learning with Early Objects Chapter 8 Applications of Arrays (Sorting and Searching) and Strings.
Lecture Set 6 The String and DateTime Data Types Part B – Characters and Strings String Properties and Methods.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Chapter 4: Do-It-Yourself Designing (Designing Interfaces)
Excel Tutorial 8 Developing an Excel Application
Visual Basic.NET Windows Programming
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 1: An Introduction to Visual Basic 2015
Chapter Eleven Handling Events.
Chapter 4: The Selection Structure
Access Project 8 Using Visual Basic for Applications (VBA) and Creating Multi-Page Forms.
Variables and Arithmetic Operations
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
CIS16 Application Development and Programming using Visual Basic.net
String Manipulation and More Controls
Introduction to Problem Solving and Control Statements
Tutorial 9 Sequential Access Files and Printing
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:

Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings

Tutorial 8: Manipulating Strings2 String Manipulation Lesson A Objectives After completing this lesson, you will be able to:  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  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

Tutorial 8: Manipulating Strings3 The Length Property of a String  In many applications, it is necessary to determine the number of characters contained in a string  You can use a string’s Length property to determine the number of characters contained in the string Debug.WriteLine(Me.ZipTextBox.Text.Length) Dim strName As String = “Paul Blackfeather” Debug.WriteLine(strName.Length) Dim strPhone As String strPhone = InputBox(“10-digit phone number”, “Phone”) Do While strPhone.Length = 10 ‘instructions strPhone = InputBox(“10-digit phone number”, “Phone”) Loop

Tutorial 8: Manipulating Strings4 Removing Characters from a String string.TrimRemoves leading and trailing spaces string.Trim(char)Removes leading and trailing char string.TrimStartRemoves leading spaces string.TrimStart(char)Removes leading char string.TrimEndRemoves trailing spaces string.TrimEnd(char)Removes trailing char

Tutorial 8: Manipulating Strings5 The Remove Method  You can use the Remove method to remove one or more characters located anywhere in a string  Figure 8-5 shows the syntax of the Remove method and includes several examples of using the method

Tutorial 8: Manipulating Strings6

7 Determining Whether a String Begins or Ends with a Specific Sequence of Characters Visual Basic.NET provides  The StartWith method for determining whether a specific sequence of characters occurs at the beginning of a string  The EndsWith method for determining whether a specific sequence of characters occurs at the end of a string

Tutorial 8: Manipulating Strings8 Accessing Characters Contained in a String  You can use the Substring method to access any number of characters in a string  The Substring method contains two arguments: startIndex and count  StartIndex is the index of the first character you want to access in the string  The count argument, which is optional, specifies the number of characters you want to access

Tutorial 8: Manipulating Strings9 More String Manipulation Functions Remove(start, count)Deletes count characters from a string starting at start StartsWith(subString)Returns true if the string starts with the subString EndsWith(subString)Returns true if the string ends with the subString Substring(start[, count])Extracts a substring of count characters starting at start Replace(oldValue, newValue)Replaces all instances of oldValue with newValue Insert(start, value)Inserts value into a string starting at start IndexOf(value[, startIndex])Returns the index of where value is found starting at startIndex Mid(target, start [, count]) = replacementString replace a specified number of characters in target with characters from another string

Tutorial 8: Manipulating Strings10 Replacing Characters in a String  You can use the Replace method to replace a sequence of characters in a string with another sequence of characters  Or, you can use it to replace the dashes in a Social Security number with the empty string

Tutorial 8: Manipulating Strings11 The Mid Statement  You can use the Mid statement to replace a specified number of characters in a string with characters from another string  Figure 8-9 shows the syntax of the Mid statement and includes several examples of using the statement

Tutorial 8: Manipulating Strings12

Tutorial 8: Manipulating Strings13 Inserting Characters within a String  You can use the Insert method to insert characters within a string  For example, you can use the Insert method to insert an employee’s middle initial within his or her name

Tutorial 8: Manipulating Strings14 Searching a String  You can use the IndexOf method to search a string to determine whether it contains a specific sequence of characters  Figure 8-11 shows the syntax and several examples of the IndexOf method  Also, examine Figure 8-12 in the textbook for more String manipulation techniques

Tutorial 8: Manipulating Strings15

Tutorial 8: Manipulating Strings16

Tutorial 8: Manipulating Strings17

Tutorial 8: Manipulating Strings18 String Conversion string.ToUpperConverts string to UPPER CASE string.ToLowerConverts string to lower case UCase(string)Converts string to UPPER CASE LCase(string)Converts string to lower case StrConv(string, format) Converts string according to format: vbStrConv.LowerCase vbStrConv.UpperCase vbStrConv.ProperCase

Tutorial 8: Manipulating Strings19 Using a Main Menu Control Lesson B Objectives After completing this lesson, you will be able to:  Add a main menu control to a form  Add main menu elements to a main menu control  Assign access keys and shortcut keys to menu elements  Code a menu item’s Click event procedure

Tutorial 8: Manipulating Strings20 Adding a Main Menu Control to a Form  You 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  As in all Windows applications, clicking a command on a menu executes the command, and clicking a submenu title opens an additional menu of options

Tutorial 8: Manipulating Strings21 Adding a Main Menu Control to a Form  Each of the options 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

Tutorial 8: Manipulating Strings22 Adding Shortcut Keys  Shortcut keys appear to the right of a menu item and allow you to select an item without opening the menu

Tutorial 8: Manipulating Strings23 Completing the Hangman Game Application Lesson C Objectives After completing this lesson, you will be able to:  Include the Substring method in a procedure  Include the Mid statement in a procedure  Include the IndexOf method in a procedure

Tutorial 8: Manipulating Strings24 Coding the Click Event Procedure for the FileNewMenuItem  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 and then click New Game  Figure 8-23 shows the pseudocode for the FileNewMenuItem’s Click event procedure

Tutorial 8: Manipulating Strings25

Tutorial 8: Manipulating Strings26 Coding the Label Controls that Contain the Letters of the Alphabet  The pseudocode shown in Figure 8-27 identifies the tasks to be performed by the Click event procedures for the 26 label controls

Tutorial 8: Manipulating Strings27