Home  |  Latest News  |  Contribute  |  F.A.Q.  |  Account  |  Scripts | About
Search ASPNut:
 
ASP Reference
Server Variables
ASP Glossary
Related Sites

Free Components

Web Colors
Entities
CSS Level 1
Encode/Decode
Glossary

Our Sponsors
ASP Nuke CMS
Free Auctions
PHP 5 Script
Funktastic Blog
ULost Directory
Team Task

 

 

 

 

 

 

 

 

 

 

 

 

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)

Orvado, San Diego Web Design

ASP Nuke CMS
Free Open Source
Content Manager
GoSwap Auctions
Buy, Sell
No Fees!

Contact Us | Contribute | About | Site Map



"Success is how high you bounce when you hit bottom." - General George Patton

©2012 San Diego Web Design - Orvado Technologies, All Rights Reserved
ASP Nut provides articles and reference documentation for Active Server Page developers.