zoukankan      html  css  js  c++  java
  • groovy基础

    字符串字面值

    def age=25

    log.info 'My age is ${age}' 

    log.info "my age is ${age}"

    log.info "My age is ${age}"

    log.info """My age is ${age} """

    字符串索引

    def greeting='hello world'
    greeting [1]    输入结果:e
    greeting[-1]              d
    greeting[1..4]       ello
    greeting[1..<5]     ello
    greeting[4..2]       oll
    greeting[4,3,7]     olr

    def hah='Hello world'
     'hello'+'world'  //把两个字符串连接起来 helloworld 
    'hello'*3   //hellohellohello 
    'hello'+3  //hello3
    hah -'o world'   //Hell  hah
    hah.length()   //11
    hah.size()      //11
    hah.count('l') //3  hah中l出现的次数
    hah.contains('ell') //true  hah中是否存在ell

    String方法:

    String te='ha'

    def hah='Hello world'
    def ha='what is hah
    def to=te.center(10,'l') // te字符串长度为10,左右均使用l填充
    te.center(10)  // te字符串长度为10,左右均使用空格填充
    log.info to
    te.concat('test')  //te后面加上字符串test
    'test'.compareToIgnoreCase('hah') //按字典顺序比较两个字符串,忽略大小写,返回int值

    ha.equalsIgnoreCase(ha) //比较恋歌字符串,忽略大小写,返回Boolean

    hah.getAt(0) // hah此字符串第0个字符
    hah.indexOf('d') //hah此字符串d的索引值
    hah.leftShift(12334) //Hello world12334
    ha.minus('is') //删除字符串中的is
    ha.next() //
    log.info ha.padLeft(30) //在字符串左侧使用空格填充字符。需共30个字符
    log.info ha.padLeft(30,'@')

    log.info ha.padRight(30) //在字符串右侧使用空格填充字符。需共30个字符
    log.info ha.padRight(30,'@')

    5.plus(5) //5+5
     hah.previous() //删除hah最后一个字符
     hah.reverse() //创建当前字符的逆序字符串

    hah <=>ha   //比较字符串
    hah.compareTo(ha) //比较字符串

  • 相关阅读:
    Android开发中常见的错误
    使用命令行的方式向GitHub中上传本地项目
    jmeter保存测试结果到文件
    转 Jmeter参数化的4种方法
    键盘各键对应的编码值(key)
    CacheHelper对缓存的控制
    Oracle存储过程
    Oricle中SQL语法
    python学习资料百度网盘分享
    一些网站学习的链接
  • 原文地址:https://www.cnblogs.com/xianhaiyan/p/4621007.html
Copyright © 2011-2022 走看看