Logo

Programming-Idioms

History of Idiom 38 > diff from v58 to v59

Edit summary for version 59 by programming-idioms.org:
[Groovy] Typo

Version 58

2020-10-10, 12:12:19

Version 59

2020-10-10, 12:54:10

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Illustration

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Illustration
Variables
t,i,j,s
Variables
t,i,j,s
Code
def t = s[i..<j]
Code
def t = s[i..<j]
Comments bubble
Uses a half-inclusive range. Throws a StringIndexOutOfBoundsException if either index extends beyond the end of the string. Indicies can be negative, in which case they count from the end of the string.
Comments bubble
Uses a half-inclusive range. Throws a StringIndexOutOfBoundsException if either index extends beyond the end of the string. Indices can be negative, in which case they count from the end of the string.
Doc URL
https://docs.groovy-lang.org/latest/html/api/groovy/lang/Range.html
Doc URL
https://docs.groovy-lang.org/latest/html/api/groovy/lang/Range.html
Demo URL
https://groovyconsole.appspot.com/script/5167058048253952
Demo URL
https://groovyconsole.appspot.com/script/5167058048253952