1.1字符串段落spa
def s = """Groovy Grails JAVA """ 輸出結果: Groovy Grails JAVA
1.2 字符串操做運算符 code
//乘法 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數字運算ip
運算符 | 名稱 | 方法 |
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() |