VBScript Mid 函數


VBScript 參考手冊 完整的 VBScript 參考手冊

Mid 函數從字串中返回指定數量的字元。

提示:請使用 Len 函數來確定字串中的字元數量。

語法

Mid(string,start[,length])

參數 描述
string 必需。從其中返回字元的字串運算式。
start 必需。規定起始位置。如果設置為大於字串中的字元數量,則返回空字元串("")。
length 可選。要返回的字元數量。

實例

實例 1

返回 1 個字元,從位置 1 開始:

<script type="text/vbscript">

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>

以上實例輸出結果:

This is a beaut


實例 3

返回所有字元,從位置 1 開始:

<script type="text/vbscript">

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>

以上實例輸出結果:

eautiful day!


VBScript 參考手冊 完整的 VBScript 參考手冊