1 / 27

Tutorial 8 Manipulating Strings

Tutorial 8 Manipulating Strings. 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

traugott
Télécharger la présentation

Tutorial 8 Manipulating Strings

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 8Manipulating Strings

  2. String ManipulationLesson 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

  3. 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

  4. Removing Characters from a String

  5. 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

  6. 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

  7. Accessing CharactersContained 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

  8. More String Manipulation Functions

  9. 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

  10. 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

  11. 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

  12. 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

  13. String Conversion

  14. Using a Main Menu ControlLesson 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

  15. Adding a Main Menu Control to a Form • You use a mainmenu 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

  16. 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

  17. Adding Shortcut Keys • Shortcut keys appear to the right of a menu item and allow you to select an item without opening the menu

  18. Completing the Hangman Game ApplicationLesson 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

  19. 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

  20. Coding the Label Controls thatContain 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

More Related