First page Back Continue Last page Overview Image

Syntactic sugar: Strings

assert 'Groovy'.length() == 6

assert 'Groovy'.substring(3) == 'ovy'

assert 'Groovy'.substring(0,2) == 'Gr'

assert 'Groovy'.take(4) == 'Groo'

assert 'GroovyDancing'[4..-1] == 'vyDancing'

assert 'Groovy'.reverse().take(4).reverse() == 'oovy'

assert 'Groovy'.replace('oo', 'a') == 'Gravy'

assert 'Groovy'.take(3).replace('o', 'u') == 'Gru'

assert 'Groovy'.replaceAll('o', 'a') == 'Graavy'

assert 'Groovy'.toLowerCase() == 'groovy'

assert 'Groovy'.toUpperCase() == 'GROOVY'

assert 'groovy'.capitalize() == 'Groovy'

assert 'grOOvy'.capitalize() == 'GrOOvy'

assert 'grOOvy'.toLowerCase().capitalize() == 'Groovy'

assert 'Groovy'.reverse() == 'yvoorG'

assert 'Groovy'.count('o') == 2

assert 'Groovy'.contains('oo') == true

assert 'Groovy'.equalsIgnoreCase('gRoOvY') == true

assert 'Groovy'.startsWith('Gr')

assert 'Groovy'.endsWith('vy')

assert 'Groovy'.isEmpty() == false

assert 'Groovy'.indexOf('v') == 4