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.


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"
Response.Write string_part

Here the output of above code


As you can see the right side three characters are collected from main string.


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


The output of the above code is here

Welcome to


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"

The ouput of the above code is here

Now let us try to collect only domain name part from a full url by using Mid function. Here is the code.

Response.Write string_part

The oupput of the above code is here

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 )

Be the first to post comment on this article :

ASP functions to handle string
Adding two or more strings in ASP
Getting the size or length of the string by using len() function
Removing blank space before and after a string using trim function
Changing lower to upper or upper to lower case of text present inside a string
Reversing a string variable by using StrReverse function
Compare two strings in different ways by using StrComp function
Collecting parts from Left , right and middle areas of a string
Checking matching of a string inside another string using InStr function
Searching and replacing strings inside another string using Replace function
Creating arrays by splitting string using split() function
Joining elements of an array to create a string variable
Line Break by replacing text line break to html line break using Replace function

Post your comments , suggestion , error , requirements etc here .

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer