Make method: substr(begin, length) which accepts negative indexes.
negative begin is counted from the end of string.
negative length is subtracted from length of string
Two arguments:
example: make string a bit shorter: .substr(0, -2)
example: extract last 3 characters: .substr(-3, 3)
Short version:
example: extract first 3 characters: .substr(3)
example: extract last 3 characters: .substr(-3)
Make method: `substr(begin, length)` which accepts negative indexes.
- negative `begin` is counted from the end of string.
- negative `length` is subtracted from length of string
Two arguments:
- example: make string a bit shorter: `.substr(0, -2)`
- example: extract last 3 characters: `.substr(-3, 3)`
Short version:
- example: extract first 3 characters: `.substr(3)`
- example: extract last 3 characters: `.substr(-3)`
Make method:
substr(begin, length)which accepts negative indexes.beginis counted from the end of string.lengthis subtracted from length of stringTwo arguments:
.substr(0, -2).substr(-3, 3)Short version:
.substr(3).substr(-3)