groovy基础
2015-07-04 17:41
411 查看
字符串字面值
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) //比较字符串
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) //比较字符串
相关文章推荐
- 面试题25:二叉树中和为某一值的路径
- Linux文件系统简介
- 截取屏幕图
- error C2440: ‘static_cast’ : cannot convert from ‘UINT (__thiscall CMenuBar::* )(CPoint)’ to ‘LRESUL
- 浏览器
- 新浪微薄份额2(分享)
- JavaScript中的this陷阱的最全收集
- ios开发流程详解
- Factorization Machines 学习笔记(四)学习算法
- [转载] tmux的使用tips
- 新手安装ubuntu问题解决(easyBCD没作用,分区,双显卡闪屏等)
- adb脚本输出android调试信息
- 最终时刻
- Mysql User表为空
- 计算几何:线段判交模板--ACM
- java web之Filter详解
- Swift开发教程--Swift的基本语法
- gcc 已知的问题及规避方案 https://gcc.gnu.org/bugs/#known
- error C2440: ‘static_cast’ : cannot convert from ‘HRESULT (__thiscall CtestpalView::* )(WPARAM,LPARA
- javascript prototype详解