The substring method of a string will return a part of the string.

If given two parameters, thense defined the range of the charactes (beginning included, end excluded). If only one parameter is given this is the beginning of the substring.

The indexing is 0 based so STRING.substring(0,3) means the first 3 characters. and STRING.substring(4,7) means the charcter number, 5,6, and 7. (index 4, 5, and 6).

examples/groovy/substring.gvy

name = 'Foo Bar Moo'
println(name)                // Foo Bar Moo
fname = name.substring(0, 3)
println(fname)               // Foo

mname = name.substring(4, 7)
println(mname)               // Bar

lname = name.substring(name.length()-3)
println(lname)               // Moo