ASP: the InStr function
One of the most used functions in ASP is InStr.
In this short article we are going to see how to use it.
startOfStr is optional and it specifies where the search will begin. By default is set to1 (first character of the string). It is required when compare is used.
stringSearched is the string to be searched. It is required.
search is the string to search inside stringSearched. It is required.
compare is optional and it can be 0 (default) or 1. If 0 (vbBinaryCompare) is used, a binary comparison will be performed, If 1 (vbTextCompare), a textual comparison will be performed. Normally we use the default value (0).
As you can see InStr is an interesting function with many possible use. It depends on what we really need to do, and what is our goal. With a little bit of imagination, we can solve a lot of complicated situations.
If you need more help on it, please use the comments section below... in the meantime happy coding!
In this short article we are going to see how to use it.
The Syntax
The InStr function has the following syntax:InStr([startOfStr,]stringSearched,search[,compare])
where:startOfStr is optional and it specifies where the search will begin. By default is set to1 (first character of the string). It is required when compare is used.
stringSearched is the string to be searched. It is required.
search is the string to search inside stringSearched. It is required.
compare is optional and it can be 0 (default) or 1. If 0 (vbBinaryCompare) is used, a binary comparison will be performed, If 1 (vbTextCompare), a textual comparison will be performed. Normally we use the default value (0).
Returned values
The function returns a value which must be evaluated. Let's see what kind of response we can obtain:- If stringSearched is "" - InStr returns 0
- If stringSearched is Null - InStr returns Null
- If search is "" - InStr returns startOfStr
- If search is Null - InStr returns Null
- If search is not found - InStr returns 0
- If search is found within stringSearched - InStr returns the position at which search is found
- If startOfStr > Len(stringSearched) - InStr returns 0
As you can see InStr is an interesting function with many possible use. It depends on what we really need to do, and what is our goal. With a little bit of imagination, we can solve a lot of complicated situations.
If you need more help on it, please use the comments section below... in the meantime happy coding!