ฟังก์ชั่น VBScript กลาง
ฟังก์ชั่นกลางผลตอบแทนตามจำนวนที่ระบุตัวอักษรจากสตริง
เคล็ดลับ: ใช้ฟังก์ชั่นเลนในการกำหนดจำนวนตัวอักษรในสตริง
ไวยากรณ์
Mid(string,start[,length])
参数 | 描述 |
---|---|
string | 必需。从其中返回字符的字符串表达式。 |
start | 必需。规定起始位置。如果设置为大于字符串中的字符数量,则返回空字符串("")。 |
length | 可选。要返回的字符数量。 |
ตัวอย่าง
ตัวอย่างที่ 1
ผลตอบแทนที่ได้ตัวละครจากตำแหน่ง 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1,1))
</script>
txt="This is a beautiful day!"
document.write(Mid(txt,1,1))
</script>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
T
ลอง»
ตัวอย่างที่ 2
ย้อนกลับไป 15 ตัวอักษรเริ่มต้นจากตำแหน่งที่ 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1,15))
</script>
txt="This is a beautiful day!"
document.write(Mid(txt,1,15))
</script>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
This is a beaut
ลอง»
ตัวอย่างที่ 3
กลับตัวอักษรทั้งหมดที่เริ่มต้นจากตำแหน่งที่ 1:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,1))
</script>
txt="This is a beautiful day!"
document.write(Mid(txt,1))
</script>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
This is a beautiful day!
ลอง»
ตัวอย่างที่ 4
กลับตัวอักษรทั้งหมดที่เริ่มต้นจากตำแหน่ง 12:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(Mid(txt,12))
</script>
txt="This is a beautiful day!"
document.write(Mid(txt,12))
</script>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
eautiful day!
ลอง»
อ้างอิง VBScript สมบูรณ์