ฟังก์ชันกลาง VBScript
❮ การอ้างอิง VBScript ที่สมบูรณ์
ฟังก์ชัน Mid จะส่งกลับจำนวนอักขระที่ระบุจากสตริง
เคล็ดลับ:ใช้ฟังก์ชัน Len เพื่อกำหนดจำนวนอักขระในสตริง
ไวยากรณ์
Mid(string,start[,length])
Parameter | Description |
---|---|
string | Required. The string expression from which characters are returned |
start | Required. Specifies the starting position. If set to greater than the number of characters in string, it returns an empty string ("") |
length | Optional. The number of characters to return |
ตัวอย่าง
ตัวอย่าง 1
ส่งกลับอักขระ 1 ตัว เริ่มต้นที่ตำแหน่ง 1:
<%
txt="This is a beautiful day!"
response.write(Mid(txt,1,1))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
T
ตัวอย่าง 2
ส่งกลับอักขระ 15 ตัว เริ่มต้นที่ตำแหน่ง 1:
<%
txt="This is a beautiful day!"
response.write(Mid(txt,1,15))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
This is a beaut
ตัวอย่างที่ 3
ส่งคืนอักขระทั้งหมดโดยเริ่มต้นที่ตำแหน่ง 1:
<%
txt="This is a beautiful day!"
response.write(Mid(txt,1))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
This is a beautiful day!
ตัวอย่างที่ 4
ส่งคืนอักขระทั้งหมด โดยเริ่มต้นที่ตำแหน่ง 12:
<%
txt="This is a beautiful day!"
response.write(Mid(txt,12))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
eautiful day!
❮ การอ้างอิง VBScript ที่สมบูรณ์