|
|
Command |
Format |
Example |
|
Left( ), Left$( ) |
Left[$](strexpr, n) |
Left("Ray Cafolla", 3) = "Ray" |
|
Right( ), Right$( ) |
Right[$](strexpr, n) |
Right("Ray Cafolla, 7) = "Cafolla |
| Mid( ), Mid$( ) | Mid[$](stringexpr, start[, length]) | Mid("Ray Cafolla",4,3) = "Caf" |
![]()
The Len( ) function takes a single string arguement and returns the length of the string.
MsgBox Len("The Rain in Spain")
Produces

The InStr( ) is one of the more complex and powerful of the string manipulation commands. It also can have either 2 or 3 parameters, but it it the first one that is optional. Let's take the easiest one first- it takes 2 arguments, both strings. It returns the integer representing the position in the first string the second string starts at. If the second string does not occur in the first string, a zero is returned.
MsgBox InStr("The rain in Spain", "Spain")
produces

If you add an integer as an optional first parameter, the search for the string begins at the given position. Thus (with 2 parameters)
MsgBox InStr("The rain in Spain", "in")
Produces

while
MsgBox InStr(8, "The rain in Spain", "in")
Produces

|
Len( ) |
Len(strexpr) |
Len("Ray Cafolla") = 11 |
|
InStr( ) |
InStr(strexpr1, strexpr2 ) InStr(start, strexpr1, strexpr2) |
Instr("Ray Cafolla", "a")
= 2 Instr("Ray Cafolla", "xyz")
= 0 Instr(14 "Ray Cafolla, "a", 0) = 6 Instr(1, "Ray Cafolla, "c",
0) = 0 |
![]()
Recall that loops can either be definite (meaning the program "knows" how many times to loop) or indefinite (meaning it is executed until some condition is met). One of the most common errors in definite loops is the "off by one" error. This can be avoided by using a special loop structure called the For..Next Loop. It looks like this:
For intCount = 1 to 10 Step 1
do something
do something
do somethingNext intCount
The commands in this loop are executed exactly 10 times. Use For..Next loops when you need a definite loop!
![]()
The ASC( ) function takes a string argument and returns the ASCII equivalent.
MsgBox ASC("A")
produces the number 65
The complementary Chr( ) function takes an integer argument and returns the string character.
MsgBox Chr(65)
produces the string "A"
![]()
The Palindrome Problem
Chapter 6 Exercises 7, 8, 9, 10, 11
![]()
![]()