Find Text with InStr() in Classic ASP

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.

Basic search

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.

Syntax with optional arguments

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.

Same search written explicitly

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 stringSearch textComparisonResult
Welcome to Plus2net.com ASP tutorialsaspBinary0
Welcome to Plus2net.com ASP tutorialsaspText25
Welcome to Plus2net.com ASP tutorialsASPBinary25
Welcome to Plus2net.com ASP tutorialsASPText25
Welcome to Plus2net.com ASP tutorials(empty string)Binary1

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().


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer