接口:字串

方法

降低

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'