接口:字符串

方法

降低

lower() 返回规则.String

返回输入字符串的小写版本。

退货

non-null rules.String小写字符串。

例子

'ABC'.lower() == 'abc'
'ABC123'.lower() == 'abc123'

火柴

matches(re) 返回规则.Boolean

对整个字符串执行正则表达式匹配。

范围

关于

规则.字符串

使用Google RE2 语法的正则表达式。

值不能为空。

退货

non-null rules.Boolean如果整个字符串匹配则为 true,否则为 false。

例子

'user@domain.com'.matches('.*@domain[.]com') == true
'banana'.matches('.*@domain[.]com') == false

代替

替换(re,sub)返回rules.String

将与正则表达式匹配的所有子字符串替换为用户提供的字符串。

范围

关于

规则.字符串

使用Google RE2 语法的正则表达式。

值不能为空。

规则.字符串

要替换的字符串。

值不能为空。

退货

non-null rules.String表示替换操作结果的字符串。如果没有子字符串与正则表达式匹配,则返回未修改的原始字符串。

例子

'banana'.replace("a", "o") == 'bonono'
'banana'.replace("ana", "ee") == 'beena'
'foo@test.com'.replace(".", "-") == '---------------' // '.' regex match all

尺寸

size() 返回规则.Integer

返回字符串中的字符数。

退货

non-null rules.Integer字符数。

例子

'a'.size() == 1
'abc'.size() == 3

分裂

split(re) 返回规则。列表

根据正则表达式分割字符串。

范围

关于

规则.字符串

使用Google RE2 语法的正则表达式。

值不能为空。

退货

non-null rules.List字符串列表。

例子

'a/b/c'.split('/') == ['a', 'b', 'c']

转UTF8

toUtf8() 返回规则.字节

返回字符串的 UTF-8 字节编码。

退货

non-null rules.Bytes包含字符串的 UTF-8 编码表示形式的字节序列。

例子

'**'.toUtf8() == b'\x2A\x2A'
'€'.toUtf8() == b'\xE2\x82\xAC'

修剪

Trim() 返回规则.String

返回删除了前导空格和尾随空格的字符串版本。

退货

non-null rules.String字符串修剪后的字符串。

例子

' a '.trim() == 'a'
'b'.trim() == 'b'

upper() 返回规则.String

返回输入字符串的大写版本。

退货

non-null rules.String大写字符串。

例子

'abc'.upper() == 'ABC'
'abc123'.upper() == 'ABC123'