Collecting part of a string part from Left , right and middle in ASP
We can remove or collect part of a string from different locations of a string by using libraray functions of VB used in ASP. We will discuss some of the functions used to collect different string parts from a given string. We will start with Right() function.
Right()
Here is the syntax of Right() function to copy characters from right side of a string.
My_string= Right( string_var, number )
Here string_var is the string variable and number is the number of characters from right to be copied. Here is an example code of Right function.
Dim string_var,string_part
string_var="Welcome to plus2net.com"
string_part=Right(string_var,3)
Response.Write string_part
Here the output of above code
com
As you can see the right side three characters are collected from main string.
Left()
Same way we can use Left() function to collect characters staring from left side of the string. Inside the above code the Right() function can be replaced by this line
string_part=Left(string_var,10)
The output of the above code is here
Welcome to
Mid
We can sue the Mid() function to collect any part of the string starting from any location. In our example code ( above ) let us try to collect only the domain name part so we will use Mid() function. Here is the syntax of the mid function
Mid(String_var, starting_from, length)
Here String_var is our string variable and starting_form is the number of characters from left side, length is the number of character to be copied starting from staring_form number.
Let us modify our example code with this line.
string_var="Welcome to plus2net.com"
string_part=Mid(string_var,12,12)
The ouput of the above code is here
plus2net.com
Now let us try to collect only domain name part from a full url by using Mid function. Here is the code.
We know that the part of the string https:// takes 7 characters and starts from left side. So the starting point we kept at 8 and then specified that 14 characters are to be collected. Note that if we specify more number of characters to be returned than actually present then rest of the whole string will be returned. So if we specify more than 14 here then also same output we will get. Try with different values in place of 14, ( You will get same output for values higher than 14 and truncated output for values less that 14 )
← ASP Home
This article is written by plus2net.com team.
plus2net.com
✖
We use cookies to improve your browsing experience. . Learn more