ฟังก์ชันตัวกรอง VBScript
❮ การอ้างอิง VBScript ที่สมบูรณ์ฟังก์ชันตัวกรองส่งกลับอาร์เรย์แบบศูนย์ที่มีชุดย่อยของอาร์เรย์สตริงตามเกณฑ์การกรอง
หมายเหตุ:หากไม่พบพารามิเตอร์ที่ตรงกัน ฟังก์ชันตัวกรองจะคืนค่าอาร์เรย์ว่าง
หมายเหตุ:หากอินพุตสตริงพารามิเตอร์เป็น Null หรือไม่ใช่อาร์เรย์แบบหนึ่งมิติ จะเกิดข้อผิดพลาดขึ้น
ไวยากรณ์
Filter(inputstrings,value[,include[,compare]])
Parameter | Description |
---|---|
inputstrings | Required. A one-dimensional array of strings to be searched |
value | Required. The string to search for |
include | Optional. A Boolean value that indicates whether to return the substrings that include or exclude value. True returns the subset of the array that contains value as a substring. False returns the subset of the array that does not contain value as a substring. Default is True. |
compare | Optional. Specifies the string comparison to use. Can have one of the following values:
|
ตัวอย่าง
ตัวอย่าง 1
ตัวกรอง: รายการที่มี "S"
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S")
for each x in b
response.write(x & "<br />")
next
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Sunday
Saturday
ตัวอย่าง 2
ตัวกรอง: รายการที่ไม่มี "S" (include=False):
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False)
for each x in b
response.write(x & "<br />")
next
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Monday
Tuesday
Wednesday
Thursday
Friday
ตัวอย่างที่ 3
ตัวกรอง: รายการที่มี "S" พร้อมการเปรียบเทียบแบบข้อความ (เปรียบเทียบ=1):
<%
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
response.write(x & "<br />")
next
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Sunday
Tuesday
Wednesday
Thursday
Saturday
❮ การอ้างอิง VBScript ที่สมบูรณ์