String slice methods return parts of a string.
Indexes are zero-based.
Returns text from `start` to the end of the string.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
Returns: string.
Example:
'abcdef'.substr(2); // 'cdef'
Returns `count` characters starting at `start`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
| `count` | number | Number of characters to return. |
Returns: string.
Example:
'abcdef'.substr(2, 3); // 'cde'
Alias for `substr(start)`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
Returns: string.
Example:
'abcdef'.slice(2); // 'cdef'
Alias for `substr(start, count)`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
| `count` | number | Number of characters to return. |
Returns: string.
Example:
'abcdef'.slice(2, 3); // 'cde'
Returns text from `start` to the end of the string.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
Returns: string.
Example:
'abcdef'.subspan(2); // 'cdef'
Returns text from `start` up to `end`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
| `end` | number | End index. |
Returns: string.
Example:
'abcdef'.subspan(2, 5); // 'cde'
Alias for `subspan(start)`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
Returns: string.
Example:
'abcdef'.span(2); // 'cdef'
Alias for `subspan(start, end)`.
| Argument | Type | Description |
|---|---|---|
| `start` | number | Zero-based start index. |
| `end` | number | End index. |
Returns: string.
Example:
'abcdef'.span(2, 5); // 'cde'
Returns the part of the string before the first matching separator text.
| Argument | Type | Description |
|---|---|---|
| `text` | any | Separator text. |
Returns: string.
Example:
'key=value'.before('='); // 'key'
Returns the part of the string after the first matching separator text.
| Argument | Type | Description |
|---|---|---|
| `text` | any | Separator text. |
Returns: string.
Example:
'key=value'.after('='); // 'value'
Previous: String Basic Methods
Next: String Parsing Methods