VBScript MidFunction


VBScript 参考手册Complete VBScript Reference Manual

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

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

Syntax

Mid(string,start[,length])

Parameter Description
string Required. A string expression from which characters are returned.
start Required. Specifies the starting position. If set to greater than the number of characters in the string, returns an empty string ("").
length Optional. The number of characters to return.

Example

Example 1

Return 1 character, starting at position 1:

<script type="text/vbscript">

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

</script>

Output of the above example:

T

Try it yourself »

Example 2

Return 15 characters, starting at position 1:

<script type="text/vbscript">

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

</script>

Output of the above example:

This is a beaut

Try it yourself »

Example 3

Return all characters, starting at position 1:

<script type="text/vbscript">

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

</script>

Output of the above example:

This is a beautiful day!

Try it yourself »

Example 4

Return all characters, starting at position 12:

<script type="text/vbscript">

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

</script>

Output of the above example:

eautiful day!

Try it yourself »

VBScript 参考手册Complete VBScript Reference Manual Other extensions