InStr
The InStr function will search for the existance of substring
within a character string. You specify the position to start searching
from, the text to search, the substring to find and, optionally, how you
would like to compare the search string.
The function returns an index to the character string where the substring
was found. The string index is based at position number 1 so that the first
position in the string (before the first character) is position 1. If the
function returns a value less than 1, it means the search string was not
found.
Dim sText sText = "The quick brown fox jumped over the lazy old dog" Response.Write "position of over = " & InStr(1, sText, "over")
The optional fourth argument is the string comparison method to use
when searching for the substring. Valid values for this argument are
shown below along with an example of how to use them.
| ASP Variable |
Value |
Meaning |
| vbBinaryCompare |
0 |
Does a binary-level comparison (ASCII codes) for the characters
in the string. This is also known as a case-sensitive comparison. |
| vbTextCompare |
1 |
Does a text-level comparison for the characters in the string.
This is also known as a case-insensitive comparison. |
' lets do a case sensative search
Response.Write "position of Over = " & InStr(1, sText, "Over", vbBinaryCompare)
Oddly enough, the first parameter for this function which indicates
where to start searching for the substring in the search text is optional.
Common programming practice is to put all of the optional arguments at the
end of the parameter list. This means you could use the InStr function
as shown below:
' leaving out the optional 1st argument
Response.Write "position of Over = " & InStr(sText, "Over", vbBinaryCompare)
|
 |

|