The Groovy string is based on java.lang.String but is more flexible than Java strings.

double quotes, single quote and slashy string

 
 
    def str 
 
    str = "Hello\" World"
    println str
    str = 'Hello" \' World'
    println str
    str = /Hello ' " *.<> \/ \ World/
    println str
 

The double quotes string is exactly like the string you used in Java. The slashy string only escape /, others interpreted literally, is very convenient for defining regular expression.

The output:

 
Hello" World
Hello" ' World
Hello ' " *.<> / \ World
 

Multiline string

 
def weather = "rainy"
def multiline = """
Any lines of string goes here
The weather is ${weather}
"""
 
def multiline2 = '''
Any lines of string goes here
The weather is ${weather}
'''
 

The output:

 
Any lines of string goes here
The weather is rainy
 
 
Any lines of string goes here
The weather is ${weather}
 

The ${weather} is embedded expression. This kind of string actually is a org.codehaus.groovy.runtime.GStringImpl instance, its more advance than java.lang.String.

String operations

Various operation performed by overloading operator, like

 
 
'Hello' + 'World' // concatenate
'Hello'*10 // repeat
'Hello'-'lo' // substring