Mid Function

Tips >>ASP Functions

The Mid function returns a specified number of characters from a string. The Mid function returns the portion of the designated string for a designated length starting from any position in the string. The Function will return the requested number of characters from a string. The Length of Characters To Pull parameter is optional.

It explains the Two Mandatory Arguments :-

  • String :- The String argument is the name of the string you wish to abbreviate. The string expression from which characters are returned. If string contains Null, Null is returned.

  • Start :- The Start argument is a numeric position anywhere in the string counting from the left side. The portion of the string to the left of this position will be discarded. The character position in string at which the part to be taken begins. If start is greater than the number of characters in string, Mid returns a zero-length string ("")

It explains One Optional Argument :-

  • Length :- The optional Length argument is the number of characters (including blanks) in the string you wish to save counting from the position designated by the Start argument.

The Syntax of the Mid function is :-

Mid(string,start[,length])

Example#1 :-

Code :-
dim txt
txt="This is a beautiful day!"
document.write(Mid(txt,1,1))
Output :-
T

Example#2 :-

Code :-
dim txt
txt="This is a beautiful day!"
document.write(Mid(txt,1,11))
Output :-
This is a b

Example#3 :-

Code :-
dim txt
txt="This is a beautiful day!"
document.write(Mid(txt,1))
Output :-
This is a beautiful day!

Example#4 :-

Code :-
dim txt
txt="This is a beautiful day!"
document.write(Mid(txt,10))
Output :-
beautiful day!

Example#5 :-

Code :-
<%
String1="michael"
Response.write Mid(String1,3,3)
%>
Output :-
cha

Example#6 :-
It explains the Start argument

Code :-
<%
=Mid("abcde fghij klmno pqrst uvwxyz", 8)
%>
Output :-

ghij klmno pqrst uvwxyz

Example#7 :-
It explains the length argument

Code :-
<% =Mid("abcde fghij klmno pqrst uvwxyz", 8, 7) %>
Output :-
ghij kl

Notes :- The MidB function is used with byte data contained in a string. Instead of specifying the number of characters, the arguments specify numbers of bytes.

 

 
E-mail : sales@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641