SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript String

substr: Part of JavaScript string

We can collect part of a string by using substr JavaScript string function. This function is helpful in extracting a part of the string. We can collect the domain part or the userid part of an email address by using this function. Here we can supply start location and total number of char from the start location ( optional ) of the string and we can get the total string within these start and total values. Here is the syntax

my_string.substr('start_value','total_value')

Here start_value and total_value are optional. If both values are not given the full string is returned. Let us start with an example.

var my_str="Welcome to www.plus2net.com"
document.write(my_str.substr(3))

The output will be come to www.plus2net.com

Now let us specify the total value and see the output.

var my_str="Welcome to www.plus2net.com"
document.write(my_str.substr(3,7))

The output will be come to

You can see we got the output from the 3rd position till we get required 7 chars.

substr function is useful in finding out the userid and domain part of an email address. Read this tutorial on how this is done.

Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer