Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
JScript
substring Method (Windows Scripting - JScript)

Updated: March 2009

Returns the substring at the specified location within a String object.

strVariable.substring(start [, end])
"String Literal".substring(start [, end]) 
start

Required. The zero-based index integer indicating the beginning of the substring.

end

Optional. The zero-based index integer indicating the end of the substring. The substring includes the characters up to, but not including, the character indicated by end.

If end is omitted, the characters from start through the end of the original string are returned.

The substring method returns a string containing the substring from start up to, but not including, end.

The substring method uses the lower value of start and end as the beginning point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) return the same substring.

If either start or end is NaN or negative, it is replaced with zero.

The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in strvar.substring(0, 3) and strvar.substring(3, 0) is three.

The following example illustrates the use of the substring method.

function SubstringDemo(){
   var s = "The quick brown fox jumped over the lazy dog.";

   // Get substring.
   var ss = s.substring(10, 15);

   // Returns "brown".
   return(ss);
}

Date

History

Reason

March 2009

Added information about end argument and changed literal in example.

Information enhancement.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker