Latest web development tutorials

VBScript Mid function

VBScript Reference Complete VBScript Reference

Mid function returns the specified number of characters from a string.

Tip: Use theLen function to determine the number of characters in a string.

grammar

Mid(string,start[,length])

参数 描述
string 必需。从其中返回字符的字符串表达式。
start 必需。规定起始位置。如果设置为大于字符串中的字符数量,则返回空字符串("")。
length 可选。要返回的字符数量。

Examples

Example 1

Returns a character from the position 1:

<script type="text/vbscript">

txt="This is a beautiful day!"
document.write(Mid(txt,1,1))

</script>

Examples of the above output:

T

try it"

Example 2

Return to 15 characters, starting from position 1:

<script type="text/vbscript">

txt="This is a beautiful day!"
document.write(Mid(txt,1,15))

</script>

Examples of the above output:

This is a beaut

try it"

Example 3

Return all the characters, starting from position 1:

<script type="text/vbscript">

txt="This is a beautiful day!"
document.write(Mid(txt,1))

</script>

Examples of the above output:

This is a beautiful day!

try it"

Example 4

Return all the characters, starting from position 12:

<script type="text/vbscript">

txt="This is a beautiful day!"
document.write(Mid(txt,12))

</script>

Examples of the above output:

eautiful day!

try it"

VBScript Reference Complete VBScript Reference