def str = "zhangjiayu"
//截取前四位字符
println str.take( 4)
//首字母小写
println str.uncapitalize()
//首字符大写
println str.capitalize()
//判断是否存在jia字符串
println str.contains("jia")
//获取字符出现了几次
println str.count("a")
//删除头两位字符
println str.drop(2)
//替换字符串
println str.collectReplacements{ it == 'a' ? 'A':null}
//查找字符串
println str.find("jian")
String test = "zhang,jia,yu"
//截取字符串 转为为字符串数组 string[]
println test.split(",")
//截取字符串 转为List
println test.tokenize(",")
Groovy 字符串操作
最新推荐文章于 2024-01-08 11:21:29 发布