VBScript Mid 函数

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 参考手册
计算机