VBScript Mid 函數(shù)
定義和用法
Mid 函數(shù)可從字符串中返回指定數(shù)目的字符。
提示:請(qǐng)使用 Len 函數(shù)來(lái)確定字符串中的字符數(shù)目。
語(yǔ)法
Mid(string,start[,length])
參數(shù) | 描述 |
---|---|
string | 必需的。從其中返回字符的字符串表達(dá)式。如果字符串包含 Null,則返回 Null。 |
start | 必需的。規(guī)定起始位置。如果設(shè)置為大于字符串中的字符數(shù)目,則返回空字符串("")。 |
length | 可選的。要返回的字符數(shù)目。如果省略或 length 超過(guò)文本的字符數(shù)(包括 start 處的字符),將返回字符串中從 start 到字符串結(jié)束的所有字符。 |
實(shí)例
例子 1
dim txt txt="This is a beautiful day!" document.write(Mid(txt,1,1))
輸出:
T
例子 2
dim txt txt="This is a beautiful day!" document.write(Mid(txt,1,11))
輸出:
This is a b
例子 3
dim txt txt="This is a beautiful day!" document.write(Mid(txt,1))
輸出:
This is a beautiful day!
例子 4
dim txt txt="This is a beautiful day!" document.write(Mid(txt,10))
輸出:
beautiful day!