VBScript InStr º¯Êý

¶¨ÒåºÍÓ÷¨

InStr º¯Êý¿É·µ»ØÒ»¸ö×Ö·û´®ÔÚÁíÒ»¸ö×Ö·û´®ÖÐÊ״γöÏÖµÄλÖá£

InStr º¯Êý¿É·µ»ØÏÂÃæµÄÖµ£º

  • Èç¹û string1 Ϊ ""£¨Á㳤¶È£© - InStr ·µ»Ø 0
  • Èç¹û string1 Ϊ Null - InStr ·µ»Ø Null
  • Èç¹û string2 Ϊ "" - InStr ·µ»Ø start
  • Èç¹û string2 Ϊ Null - InStr ·µ»Ø Null
  • Èç¹û string2 ûÓÐÕÒµ½ - InStr ·µ»Ø 0
  • Èç¹ûÔÚ string1 ÖÐÕÒµ½ string2£¬InStr ·µ»ØÕÒµ½Æ¥Åä×Ö·û´®µÄλÖá£
  • Èç¹û start > Len(string1) - InStr ·µ»Ø 0

Ìáʾ£ºÇë²ÎÔÄ InStrRev º¯Êý¡£

Óï·¨

InStr([start,]string1,string2[,compare])
²ÎÊý ÃèÊö
start ¿ÉÑ¡µÄ¡£¹æ¶¨Ã¿´ÎËÑË÷µÄÆðʼλÖá£Ä¬ÈÏÊÇËÑË÷ÆðʼλÖÃÊǵÚÒ»¸ö×Ö·û¡£Èç¹ûÒѹ涨 compare ²ÎÊý£¬Ôò±ØÐëÓд˲ÎÊý¡£
string1 ±ØÐèµÄ¡£ÐèÒª±»ËÑË÷µÄ×Ö·û´®¡£
string2 ±ØÐèµÄ¡£ÐèËÑË÷µÄ×Ö·û´®¡£
compare

±ØÐèµÄ¡£¹æ¶¨ÒªÊ¹ÓõÄ×Ö·û´®±È½ÏÀàÐÍ¡£Ä¬ÈÏÊÇ 0 ¡£¿É²ÉÓÃÏÂÁÐÖµ£º

  • 0 = vbBinaryCompare - Ö´Ðжþ½øÖƱȽϡ£
  • 1 = vbTextCompare - Ö´ÐÐÎı¾±È½Ï¡£

ʵÀý

Àý×Ó 1

dim txt,pos
txt="This is a beautiful day!"
pos=InStr(txt,"his")
document.write(pos)

Êä³ö£º

2

Àý×Ó 2

dim txt,pos
txt="This is a beautiful day!"
'A textual comparison starting at position 4
pos=InStr(4,txt,"is",1)
document.write(pos)

Êä³ö£º

6

Àý×Ó 3

dim txt,pos
txt="This is a beautiful day!"
'A binary comparison starting at position 1
pos=InStr(1,txt,"B",0)
document.write(pos)

Êä³ö£º

0
VUE