VBScript InStr လက်တွေ့

အသုံးပြုခြင်း နှင့် အဆို

InStr လက်တွေ့ အပြီးအဝှမ်း ကို တစ်ခုခုသော စကားလုံး ကို တစ်ခုခုသော စကားလုံး တွင် ပထမဆုံး တွေ့ရှိသော အစွဲ ကို ပြန်လည်ပေးသည်

InStr လက်တွေ့ အပြီးအဝှမ်း ကို ပြန်လည်ပေးနိုင်သော အရာများ:

  • string1 အား "" (အကွက်အပိုင်း) ကို ပြန်လည်ပေးခြင်း မရှိလျှင် - InStr အပြီးအဝှမ်း 0 ကို ပြန်လည်ပေးသည်
  • string1 အား Null ကို ပြန်လည်ပေးခြင်း မရှိလျှင် - InStr အပြီးအဝှမ်း Null ကို ပြန်လည်ပေးသည်
  • string2 အား "" (ပဲချင်း) ကို ပြန်လည်ပေးခြင်း မရှိလျှင် - InStr အပြီးအဝှမ်း အစပျိုး ကို ပြန်လည်ပေးသည်
  • string2 အား Null ကို ပြန်လည်ပေးခြင်း မရှိလျှင် - InStr အပြီးအဝှမ်း Null ကို ပြန်လည်ပေးသည်
  • string2 ကို တွေ့ရှိခြင်း မရှိလျှင် - InStr အပြီးအဝှမ်း 0 ကို ပြန်လည်ပေးသည်
  • string1 တွင် string2 ကို တွေ့ရှိခဲ့လျှင် InStr အပြီးအဝှမ်း တွေ့ရှိသော စကားလုံး အစွဲ ကို ပြန်လည်ပေးသည်
  • အစပျိုး > Len(string1) - InStr အပြီးအဝှမ်း ကို လျှင် 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