VBScript InStr Funksie


❮ Voltooi VBScript-verwysing

Die InStr-funksie gee die posisie van die eerste voorkoms van een string binne 'n ander terug.

Die InStr-funksie kan die volgende waardes terugstuur:

  • As string1 "" is - InStr gee 0
  • As string1 Null is - InStr gee Null terug
  • As string2 "" is - InStr gee begin terug
  • As string2 Null is - InStr gee Null terug
  • As string2 nie gevind word nie - InStr gee 0
  • As string2 binne string1 gevind word - InStr gee die posisie terug waarop passing gevind word
  • As begin > Len(string1) - InStr gee 0

Wenk: Kyk ook na die InStrRev-funksie

Sintaksis

InStr([start,]string1,string2[,compare])

Parameter Description
start Optional. Specifies the starting position for each search. The search begins at the first character position (1) by default. This parameter is required if compare is specified
string1 Required. The string to be searched
string2 Required. The string expression to search for
compare Optional. Specifies the string comparison to use. Default is 0

Can have one of the following values:

  • 0 = vbBinaryCompare - Perform a binary comparison
  • 1 = vbTextCompare - Perform a textual comparison

Voorbeelde

Voorbeeld 1

<%

txt="This is a beautiful day!"
response.write(InStr(txt,"beautiful"))

%>

Die afvoer van die kode hierbo sal wees:

11

Voorbeeld 2

Soek die letter "i" deur verskillende beginposisies te gebruik:

<%

txt="This is a beautiful day!"
response.write(InStr(1,txt,"i") & "<br />")
response.write(InStr(7,txt,"i") & "<br />")

%>

Die afvoer van die kode hierbo sal wees:

3
16

Voorbeeld 3

Vind die letter "t", met tekstuele en binêre vergelyking:

<%

txt="This is a beautiful day!"
response.write(InStr(1,txt,"t",1) & "<br />")
response.write(InStr(1,txt,"t",0) & "<br />")

%>

Die afvoer van die kode hierbo sal wees:

1
15

❮ Voltooi VBScript-verwysing