String.substring() MethodNameString.substring() Method---return a substring of a stringAvailabilityNavigator 2.0, Internet Explorer 3.0 Synopsis
string.substring(from, to) Arguments
ReturnsA new string, of length to-from, which contains a substring of string. The new string contains characters copied from positions from to to-1 of string. DescriptionString.substring() returns the specified substring of string. If from equals to, String.substring() returns an empty (length 0) string. If from is greater than to, this method first swaps the two arguments before proceeding. UsageString.substring() can be a confusing function to use. It is important to remember that the character at position from is included in the substring, but that the character at position to is not included in the substring. One notable feature of assigning the arguments this way is that the length of the returned substring is always equal to to-from. Often it is more convenient to extract a substring of a string by specifying the start character and the desired length of the substring. You can do this with a function like the following:
function substring2(string, start, length) { return string.substring(start, start+length); } |
|