- 字符串
1.1字符串段落
def s = """Groovy
Grails
JAVA
""" 输出结果:
Groovy
Grails
JAVA
1.2字符串运算符操作:
//乘法
assert "hellohello" == "hello" * 2 //减法
def st1 = "helloWorld"
def st2 = "World"
assert "hello" == st1 - st2 //截取字符串
def st1 = "helloWorld"
assert "hello" == st1[0..4]
assert "World" == st1[5..9]
assert "World" == st1[-1..-5] //从右边截取字符串
1.3数字运算
运算符 | 名称 | 方法 |
a + b | 加 | a.plus(b) |
a | b | 减 | a.minus(b) |
a * b | 乘 | a.multiply(b) |
a / b | 除 | a.div(b) |
a % b | 取余 | a.mod(b) |
a++ | 后自增 | a.next() |
a-- | 后自减 | a.previous() |