String.substr
String.substr
Function
Truncate the string by length starting from the specified position.
Syntax
string.substr(start, length)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| start | Int | No | 0 | Starting character position; a negative number means counting backwards from the end. |
| length | Int | No | String length | Truncation length; negative numbers are treated as 0. |
Return value
| Type | Description |
|---|---|
| String | Returns the new string after interception. |
Example
text = 'hello BT' result = text.substr(6, 2) // Output: BT print result
Notes
- Unlike the second parameter of slice, the second parameter of substr represents the length.