What is the use of the InStr() function in VBScript?
The InStr Function
The InStr function returns the first occurrence of one string within another string. Generally, the search happens from left to right.
The InStr Function Syntax is as follows:
InStr([start,]string1,string2[,compare])
Description
0 = vbBinaryCompare - Performs Binary Comparison(Default)
1 = vbTextCompare - Performs Text ComparisonThe InStr Function Example is as below:
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
var = "SlightBook Website"
document.write("Line 1 : " & InStr(1,var,"i") & "<br />")
document.write("Line 2 : " & InStr(7,var,"0") & "<br />")
document.write("Line 3 : " & InStr(1,var,"f",1) & "<br />")
document.write("Line 4 : " & InStr(1,var,"t",0) & "<br />")
document.write("Line 5 : " & InStr(1,var,"l") & "<br />")
document.write("Line 6 : " & InStr(7,var,"i") & "<br />")
document.write("Line 7 : " & InStr(var,"We"))
</script>
</body>
</html>
The above script will produce the following result when you save it as .html and execute it in the browser:
Line 1: 3
Line 2: 0
Line 3: 8
Line 4: 6
Line 5: 2
Line 6: 16
Line 7: 12
What is the use of the Chr() function in VBScript?
What is the use of the Asc() function in VBScript?
What is the use of the Len() function in VBScript?
What is the use of Mid() function in VBScript?
What is the use of Spaces() function in VBScript?