首页 > 其他 > 详细

Groovy 字符串那点儿事儿

时间:2020-01-03 12:12:02      阅读:79      评论:0      收藏:0      [点我收藏+]

 

可以直接用+

assert ‘ab‘ == ‘a‘ + ‘b‘

 

支持多行

def aMultilineString = ‘‘‘line one
line two
line three‘‘‘

 out:

Fri Jan 03 11:14:58 CST 2020: INFO: line one
line two
line three

如果定义多行字符串时有缩进,可以去掉,下面俩方法就行

import java.lang.String
import java.lang.GString
String#stripIndent() String#stripMargin()

 

巧合了,字符在行开头,下面两种一样

def aMultilineString1 = ‘‘‘
line one
line two
line three‘‘‘

def aMultilineString2 = ‘‘‘\n
line one
line two
line three‘‘‘

log.info aMultilineString1
log.info aMultilineString2

 技术分享图片

 

 

让字符串里出现 引号 和反斜杠

技术分享图片

 

 

 

下面这些是用反斜杠也能出现在字符串里

技术分享图片

 

 

技术分享图片

 

知识来源官网

http://docs.groovy-lang.org/docs/latest/html/documentation/#_shebang_line

Groovy 字符串那点儿事儿

原文:https://www.cnblogs.com/baxianhua/p/12144114.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!