1. 字符串

    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()

 

相关文章:

  • 2021-05-05
  • 2022-03-06
  • 2021-11-22
  • 2021-09-01
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-30
  • 2021-08-09
  • 2021-08-08
  • 2021-07-28
  • 2021-06-26
  • 2022-12-23
  • 2022-01-18
相关资源
相似解决方案