substr (JavaScript)
Gets a substring.
Defined in
String (Standard - JavaScript)| Parameters | Description |
|---|---|
| start | The beginning index, inclusive, where 0 is the first index in the string. |
| length | The number of characters in the substring. |
| Return value | Description |
|---|---|
| string | The substring. |
Usage
This method gets characters starting at the index specified by parameter 1.Examples
(1) The following example prints <<<Moscow Tokyo>>> (index 8 to the end).function p(stuff) {
print("<<<" + stuff + ">>>");
}
var cities : String;
var ss : string;
try {
cities = new String("Paris Moscow Tokyo");
ss = cities.substr(8);
p(ss);
} catch(e) {
p("Error = " + e);
}
(2) The following example prints <<<Moscow>>> (index 8 to index 13, inclusive) from the string.
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var cities : String;
var ss : string;
try {
cities = new String("Paris Moscow Tokyo");
ss = cities.substr(8, 6);
p(ss);
} catch(e) {
p("Error = " + e);
}