Title: Microsoft Visual Basic 2005: Reloaded Second Edition
1Microsoft Visual Basic 2005 Reloaded Second
Edition
- Chapter 6
- String Manipulation and More Controls
2Objectives
- 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
3Objectives (continued)
- Access characters contained in a string
- Compare strings
- Include radio buttons in an interface
- Include check boxes in an interface
4Manipulating Strings in Visual Basic
- Most applications need to manipulate string data
in some fashion - String properties and methods are used to
manipulate string data
5Determining the Number of Characters Contained in
a String
6Determining the Number of Characters Contained in
a String (continued)
7Determining the Number of Characters Contained in
a String (continued)
8Determining the Number of Characters Contained in
a String (continued)
9Removing 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
10Removing Characters from a String (continued)
11Removing 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
12Removing Characters from a String (continued)
13Removing Characters from a String (continued)
14The Remove Method
- Remove method
- 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)
15The Remove Method (continued)
16The Remove Method (continued)
17The Remove Method (continued)
18The Remove Method (continued)
19Replacing Characters in a String
- Replace method replaces a sequence of characters
in a string with another sequence of characters
20Replacing Characters in a String (continued)
21Replacing Characters in a String (continued)
22Replacing Characters in a String (continued)
23Replacing Characters in a String (continued)
24The 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
25The Mid Statement (continued)
- Character position of characters in the string
starts with 1 (not the same as index) - Count argument is optional
26The Mid Statement (continued)
27The Mid Statement (continued)
28The Mid Statement (continued)
29Inserting 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
30Inserting Characters in a String (continued)
31Inserting Characters in a String (continued)
32Inserting Characters in a String (continued)
33Inserting Characters in a String (continued)
34Inserting Characters in a String (continued)