InStr VBScript Function

Syntax: InStr(StringToSearch, StringToFind)
The Function will return the position of the first occurence of StringToFind within StringToSearch. The Function will return 0 if StringToFind is not found.

Example 1:

<%
String1="michael"
String2="wall"
If InStr(String1,String2)>0 Then
Response.write("String1 contains String2")
Else
Response.write("String1 is not in String2")
End if
%>

Example 2:

<%
String1="It's taken me 4 years of work"
String2="t"
Location= Instr(String1,String2)
response.write Location
%>

Result displayed on the screen would be:
2

Note you can set the starting position for each search. If omitted, search begins at the first character position.

Example 3:

<%
String1="It's taken me 4 years of work"
String2="t"
Location= Instr(3,String1,String2)
response.write Location
%>

Result displayed on the screen would be:
6


Other useful VBScript functions for Parsing String

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.