ฟังก์ชันVBScript InStrRev
❮ การอ้างอิง VBScript ที่สมบูรณ์
ฟังก์ชัน InStrRev ส่งกลับตำแหน่งการเกิดขึ้นครั้งแรกของสตริงหนึ่งภายในอีกสตริงหนึ่ง การค้นหาเริ่มต้นจากจุดสิ้นสุดของสตริง แต่ตำแหน่งที่ส่งคืนจะนับจากจุดเริ่มต้นของสตริง
ฟังก์ชัน InStrRev สามารถคืนค่าต่อไปนี้:
- หาก string1 คือ "" - InStrRev คืนค่า 0
- หาก string1 เป็น Null - InStrRev จะคืนค่า Null
- หาก string2 เป็น "" - InStrRev จะคืนค่า start
- หาก string2 เป็น Null - InStrRev จะคืนค่า Null
- หากไม่พบ string2 - InStrRev คืนค่า 0
- หากพบ string2 ภายใน string1 - InStrRev จะส่งกลับตำแหน่งที่พบที่ตรงกัน
- ถ้า start > Len(string1) - InStrRev คืนค่า 0
เคล็ดลับ:ดูฟังก์ชัน InStr ด้วย
ไวยากรณ์
InStrRev(string1,string2[,start[,compare]])
Parameter | Description |
---|---|
string1 | Required. The string to be searched |
string2 | Required. The string expression to search for |
start | Optional. Specifies the starting position for each search. The search begins at the last character position by default (-1) |
compare | Optional. Specifies the string comparison to use.
Default is 0 Can have one of the following values:
|
ตัวอย่าง
ตัวอย่าง 1
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"beautiful"))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
11
ตัวอย่าง 2
ค้นหาตัวอักษร "i" โดยใช้ตำแหน่งเริ่มต้นต่างกัน:
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"i",-1) & "<br />")
response.write(InStrRev(txt,"i",7) & "<br />")
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
16
6
ตัวอย่างที่ 3
การหาตัวอักษร "T" พร้อมการเปรียบเทียบข้อความและเลขฐานสอง:
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"T",-1,1) & "<br />")
response.write(InStrRev(txt,"T",-1,0) & "<br />")
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
15
1
❮ การอ้างอิง VBScript ที่สมบูรณ์