Text.Contains
語法
Text.Contains(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical
關於
偵測 text
是否包含值 substring
。 如果找到值,則會傳回 true。 此函式不支援萬用字元或規則運算式。
選擇性引數 comparer
可用來指定不區分大小寫或文化特性和地區設定感知的比較。 下列內建比較子可用於公式語言:
- Comparer.Ordinal:用來執行區分大小寫的順序性比較
- Comparer.OrdinalIgnoreCase:用來執行不區分大小寫的序數比較
- Comparer.FromCulture:用來執行文化特性感知比較
如果第一個引數為 null,則此函式會傳回 null。
所有字元均按字面意義處理。 例如,"DR"、" DR"、"DR " 和 " DR " 不會視為彼此相等。
範例 1
找出文字 "Hello World" 是否包含 "Hello"。
使用方式
Text.Contains("Hello World", "Hello")
輸出
true
範例 2
找出文字 "Hello World" 是否包含 "hello"。
使用方式
Text.Contains("Hello World", "hello")
輸出
false
範例 3
使用區分大小寫的比較子來尋找文字 "Hello World" 是否包含 "hello"。
使用方式
Text.Contains("Hello World", "hello", Comparer.OrdinalIgnoreCase)
輸出
true
範例 4
在帳戶代碼中包含 "A-" 或 "7" 的資料表中尋找資料列。
使用方式
let
Source = #table(type table [Account Code = text, Posted Date = date, Sales = number],
{
{"US-2004", #date(2023,1,20), 580},
{"CA-8843", #date(2023,7,18), 280},
{"PA-1274", #date(2022,1,12), 90},
{"PA-4323", #date(2023,4,14), 187},
{"US-1200", #date(2022,12,14), 350},
{"PTY-507", #date(2023,6,4), 110}
}),
#"Filtered rows" = Table.SelectRows(
Source,
each Text.Contains([Account Code], "A-") or
Text.Contains([Account Code], "7"))
in
#"Filtered rows"
輸出
#table(type table [Account Code = text, Posted Date = date, Sales = number],
{
{"CA-8843", #date(2023,7,18), 280},
{"PA-1274", #date(2022,1,12), 90},
{"PA-4323", #date(2023,4,14), 187},
{"PTY-507", #date(2023,6,4), 110}
})