VBScript Mid Function



Mid

The Mid Function returns a specified number of characters from a given input string.

Syntax

Mid(String,start[,Length])
  • String, a Required Parameter. Input String from which the specified number of characters to be returned.

  • Start, a Required Parameter. An Integer, which Specifies starting position of the string.

  • Length, an Optional Parameter. An Integer, which specifies the number of characters to be returned.

Example

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         var = "Microsoft VBScript"
         document.write("Line 1 : " & Mid(var,2) & "<br />")
         document.write("Line 2 : " & Mid(var,2,5) & "<br />")
         document.write("Line 3 : " & Mid(var,5,7) & "<br />")

      </script>
   </body>
</html>

When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −

Line 1 : icrosoft VBScript
Line 2 : icros
Line 3 : osoft V
vbscript_strings.htm
Advertisements