Groovy 字符串那点儿事儿

可以直接用+

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

猜你喜欢

转载自www.cnblogs.com/baxianhua/p/12144114.html
今日推荐