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 substring() METHOD

The substr() method extracts characters from a string between two specified positions and returns the extacted part as new string.

The substring() method takes a required starting position as a number and an optional stop position. If the optional stop position 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.substring(startposition, stopposition[optional]);

Example Without The Optional Stop Position:

<script type="text/javascript">

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

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

</script>

Will output:



Example With The Optional Stop Position:

<script type="text/javascript">

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

document.write(text.substring(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