本页内容
上一节: Func_trim 下一节: Func_replace

VBScript Mid 函数

完整的 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 参考手册

上一节: Func_trim 下一节: Func_replace
此页面最后编辑于2022年8月17日 (星期三) 17:58。