JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

JAVASCRIPT substr() METHOD

The substr() method extracts characters from a string where the extraction starts from a specified starting position and returns the extacted part as new string.

The substr() method takes a required starting position as a number and an optional desired string length of the extracted part. If the desired string length is not specified, then the extracted string will be from starting position to end of main string.

Remember: the first position of a string is 0 and not 1.

The general format is:

string.substr(startingposition, length[optional]);

Example Without The Optional Length:

<script type="text/javascript">

var text="My name is John Doe.";

document.write(text.substr(3));

</script>

Will output:



Example With The Optional Length:

<script type="text/javascript">

var text="My name is John Doe.";

document.write(text.substr(3, 4));

</script>

Will output:



See Also:

anchor() big()
blink() bold()
charAt() charCodeAt()
concat() fixed()
fontcolor() fontsize()
fromCharCode() indexOf ()
italics () lastIndexOf()
link() match()
replace () search()
slice() small()
split() strike()
sub() substr()
substring() sup()
toLowerCase() toUpperCase()
toSource() valueOf ()

Home | Privacy Policy | Terms Of Use | Contact Us