InStr() returns the 1-based position of the first occurrence of one string inside another. It returns 0 when the requested text is not found.
Dim string_var, string_part
string_var="Welcome to Plus2net.com ASP tutorials"
string_part="ASP"
Response.Write InStr(string_var, string_part)
The result is 25.
InStr(start, string_var, string_part, comparetype)
If the compare argument is supplied, the starting position is also required. Use vbBinaryCompare for binary comparison or vbTextCompare for textual comparison.
Dim string_var, string_part
string_var="Welcome to Plus2net.com ASP tutorials"
string_part="ASP"
Response.Write InStr(1, string_var, string_part, vbBinaryCompare)
| Main string | Search text | Comparison | Result |
|---|---|---|---|
| Welcome to Plus2net.com ASP tutorials | asp | Binary | 0 |
| Welcome to Plus2net.com ASP tutorials | asp | Text | 25 |
| Welcome to Plus2net.com ASP tutorials | ASP | Binary | 25 |
| Welcome to Plus2net.com ASP tutorials | ASP | Text | 25 |
| Welcome to Plus2net.com ASP tutorials | (empty string) | Binary | 1 |
If either searched string is Null, the result is Null. For byte-position searches there is also InStrB(), but ordinary text handling generally uses InStr().
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.