Download presentation
Presentation is loading. Please wait.
Published byJodie Morton Modified over 5 years ago
1
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 6 String Manipulation and More Controls
2
Objectives After studying this chapter, you should be able to:
Determine the number of characters contained in a string Remove characters from a string Replace one or more characters in a string Insert characters within a string Search a string for one or more characters Microsoft Visual Basic 2005: Reloaded, Second Edition
3
Objectives (continued)
Access characters contained in a string Compare strings Include radio buttons in an interface Include check boxes in an interface Microsoft Visual Basic 2005: Reloaded, Second Edition
4
Manipulating Strings in Visual Basic
Most applications need to manipulate string data in some fashion String properties and methods are used to manipulate string data Microsoft Visual Basic 2005: Reloaded, Second Edition
5
Determining the Number of Characters Contained in a String
Microsoft Visual Basic 2005: Reloaded, Second Edition
6
Determining the Number of Characters Contained in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
7
Determining the Number of Characters Contained in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
8
Determining the Number of Characters Contained in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
9
Removing Characters from a String
TrimStart method: removes one or more characters from the beginning of a string TrimEnd method: removes one or more characters from the end of a string Trim method: removes one or more characters from both the beginning and end of a string Each of these methods returns a string with the appropriate characters removed Microsoft Visual Basic 2005: Reloaded, Second Edition
10
Removing Characters from a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
11
Removing Characters from a String (continued)
trimChars argument: Comma-separated list of characters to be removed If omitted, spaces will be removed Default value is the space character: “ ” Microsoft Visual Basic 2005: Reloaded, Second Edition
12
Removing Characters from a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
13
Removing Characters from a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
14
The Remove Method Remove method: Index:
Removes characters from a string Can remove one or more characters located anywhere in the string Returns a string with the appropriate characters removed Index: The position of a character in a string Is zero-relative (starts with 0 as first position) Microsoft Visual Basic 2005: Reloaded, Second Edition
15
The Remove Method (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
16
The Remove Method (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
17
The Remove Method (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
18
The Remove Method (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
19
Replacing Characters in a String
Replace method: replaces a sequence of characters in a string with another sequence of characters Microsoft Visual Basic 2005: Reloaded, Second Edition
20
Replacing Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
21
Replacing Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
22
Replacing Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
23
Replacing Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
24
The Mid Statement Mid statement:
Replaces a specified number of characters in a string with characters from another string targetString argument: the string in which characters are to be replaced replacementString argument: the replacement characters start argument: the starting position for the replacement count argument: number of characters to replace Microsoft Visual Basic 2005: Reloaded, Second Edition
25
The Mid Statement (continued)
Character position of characters in the string starts with 1 (not the same as index) Count argument is optional Microsoft Visual Basic 2005: Reloaded, Second Edition
26
The Mid Statement (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
27
The Mid Statement (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
28
The Mid Statement (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
29
Inserting Characters in a String
PadLeft method: inserts characters at the beginning of a string PadRight method: inserts characters at the end of a string length argument: represents the total length of the desired resulting string character argument: The character used to pad the string Default value is the space character Microsoft Visual Basic 2005: Reloaded, Second Edition
30
Inserting Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
31
Inserting Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
32
Inserting Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
33
Inserting Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
34
Inserting Characters in a String (continued)
Microsoft Visual Basic 2005: Reloaded, Second Edition
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.