字串函式 string-functions
字串函式可讓您操控和處理歷程運算式中的文字值。 這些功能對於客戶歷程中的文書處理、驗證、轉換和分析至關重要。
當您需要以下動作時,請使用字串函式:
- 串連並合併多個文字值(concat)
- 搜尋特定文字模式或子字串(contain,containIgnoreCase,indexOf,lastIndexOf,matchRegExp)
- 比較具有區分大小寫或不區分大小寫相符專案(equalIgnoreCase, notEqualIgnoreCase)的字串
- 檢查字串開始和結束(startWith,startWithIgnoreCase,endWith,endWithIgnoreCase)
- 使用子字串作業擷取部分文字(substr)
- 將文字轉換為大寫或小寫(upper, lower, trim)
- 檢查字串是否為空白或包含特定值(isEmpty, isNotEmpty)
- 以新值取代文字模式(replace,replaceAll)
- 將字串分割為陣列以供進一步處理(分割)
- 取得字串長度(length)或產生唯一識別碼(uuid)
字串函式提供完整的文字操控功能,可讓您根據歷程運算式中的文字內容,進行複雜的資料處理和條件式邏輯。
concat concat
串連兩個字串引數或字串清單。
concat(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 清單 | listString |
| 字串 | 字串 |
concat(<string>,<string>)
concat(<listString>)
傳回字串。
concat("Hello","World")
傳回「HelloWorld」。
concat(["Hello"," ","World"])
傳回「Hello World」。
contain contain
檢查第二個引數字串是否包含在第一個引數字串中。
contain(<parameters>)- 字串
contain(<string>,<string>)
傳回布林值。
contain("rowing is great", "great")
傳回true。
containIgnoreCase containIgnoreCase
檢查第二個引數字串是否包含在第一個引數字串中,而不考慮大小寫。
containIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 搜尋的字串 | 字串 |
containIgnoreCase(<string>,<string>)
傳回布林值。
containIgnoreCase("rowing is great", "GREAT")
傳回true。
endWith endWith
如果第二個引數是第一個引數的尾碼,則傳回true。
endWith(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 尾碼 | 字串 |
endWith(<string>,<string>)
傳回布林值。
endWith("Hello World", "World")
傳回true。
endWith("Hello World", "Hello")
傳回false。
endWithIgnoreCase endWithIgnoreCase
檢查第一個引數字串是否以特定字串(第二個引數字串)結尾,並未考慮大小寫。
endWithIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 尾碼 | 字串 |
endWithIgnoreCase(<string>,<string>)
傳回布林值。
endWithIgnoreCase("rowing is great", "AT")
傳回true。
equalIgnoreCase equalIgnoreCase
比較第一個引數字串與第二個引數字串,忽略大小寫考量。
equalIgnoreCase(<parameters>)- 字串
equalIgnoreCase(<string>,<string>)
傳回布林值。
equalIgnoreCase("rowing is great", "rowing is GREAT")
傳回true。
indexOf indexOf
傳回第二個引數在第一個引數中第一次出現的位置。 如果沒有相符專案,則傳回–1。
indexOf(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 指定值 | 字串 |
indexOf(<string>,<string>)
傳回整數。
indexOf("Hello", "l")
傳回2。
說明:
在「Hello」中,「l」的第一次出現位置為位置2。
IsEmpty isEmpty
如果引數中的字串沒有字元,則傳回true。
isEmpty(<parameters>)- 字串
isEmpty(<string>)
傳回布林值。
isEmpty("")
傳回true。
isEmpty("Hello World")
傳回false。
isEmpty(<null>)
傳回false。
isNotEmpty isNotEmpty
如果引數中的字串不是空的,則傳回true。
isNotEmpty(<parameters>)- 字串
isNotEmpty(<string>)
傳回布林值。
isNotEmpty("")
傳回false。
isNotEmpty("hello")
傳回true。
lastIndexOf lastIndexOf
傳回第二個引數最後一次出現的位置(在第一個引數中)。 如果沒有相符專案,則傳回–1。
lastIndexOf(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 指定值 | 字串 |
lastIndexOf(<string>,<string>)
傳回整數。
lastIndexOf("Hello", "l")
傳回3。
說明:
在「Hello」中,「l」的最後一次出現位於位置3。
長度 length
傳回引數中字串運算式的字元數。
length(<parameters>)- 字串
length(<string>)
傳回整數。
length("Hello World")
傳回11。
lower lower
傳回小寫版本的引數。
lower(<parameter>)- 字串
lower(<string>)
傳回字串。
lower("A")
傳回「a」。
matchRegExp matchRegExp
如果第一個引數中的字串符合第二個引數中的規則運算式,則傳回true。 如需詳細資訊,請參閱此頁面。
matchRegExp(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| regexp | 字串 |
matchRegExp(<string>,<string>)
傳回布林值。
matchRegExp("12345", "\\d+")
傳回true。
notEqualIgnoreCase notEqualIgnoreCase
檢查第一個引數字串是否與第二個引數字串不同,忽略大小寫考量。
notEqualIgnoreCase(<parameters>)- 字串
notEqualIgnoreCase(<string>,<string>)
傳回布林值。
notEqualIgnoreCase(@event{iOSPushPermissionAllowed.device.model}, "iPad")replace replace
以基礎字串中的取代字串取代符合目標字串的第一個專案。
例如,取代會從字串的開頭到結尾進行,將字串「aaa」中的「aa」取代為「b」將會產生「ba」而非「ab」。
replace(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 類型 |
| 基底 | 字串 |
| Target | 字串(RegExp) |
| 取代 | 字串 |
replace(<base>,<target>,<replacement>)
傳回字串。
replace("Hello World", "l", "x")
傳回「Hexlo World」。
具有RegExp的範例:
由於目標引數是RegExp,因此根據您要取代的字串,您可能需要將部分字元逸出。 其範例如下:
- 要評估的字串:
|OFFER_A|OFFER_B - 由設定檔屬性
#{ExperiencePlatform.myFieldGroup.profile.myOffers}提供 - 要取代的字串:
|OFFER_A - 字串取代為:
'' - 您必須在
|字元前新增\\。
運算式為:
replace(#{ExperiencePlatform.myFieldGroup.profile.myOffers}, '\\|OFFER_A', '')
傳回的字串是: |OFFER_B
您也可以建置要由指定屬性取代的字串:
replace(#{ExperiencePlatform.myFieldGroup.profile.myOffers}, '\\|' + #{ExperiencePlatform.myFieldGroup.profile.myOfferCode}, '')
replaceAll replaceAll
以基礎字串中的取代字串取代所有符合目標字串的相符專案。
例如,取代會從字串的開頭到結尾進行,將字串「aaa」中的「aa」取代為「b」將會產生「ba」而非「ab」。
replaceAll(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 類型 |
| 基底 | 字串 |
| Target | 字串(RegExp) |
| 取代 | 字串 |
replaceAll(<baseString>,<sourceString>,<replacementString>)
傳回字串。
replaceAll("Hello World", "l", "x")
傳回「Hexxo Worxd」。
由於目標引數是RegExp,因此根據您要取代的字串,您可能需要將部分字元逸出。 請參考取代函式中的範例。
split split
以分隔字串分割第一個引數字串(第二個引數字串,可以是規則運算式),以產生字串(代號)清單。
split(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 輸入字串 | 字串 |
| 分隔符號字串 | 字串 |
split(<input string>, <separator string>)
傳回listString。
split("A_B_C", "_")
傳回["A","B","C"]
具有下列值的事件欄位「event.appVersion」範例:「20.45.2.3434」
split(@event{event.appVersion}, "\\.")
傳回["20", "45", "2", "3434"]
startWith startWith
如果第二個引數是第一個引數的前置詞,則傳回true。
startWith(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 前置詞 | 字串 |
startWith(<string>,<string>)
傳回布林值。
startWith("Hello World", "Hello")
傳回true。
startWith("Hello World", "World")
傳回false。
startWithIgnoreCase startWithIgnoreCase
如果第二個引數是第一個引數的前置詞,則傳回true,而不考慮大小寫。
startWithIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| 前置詞 | 字串 |
startWithIgnoreCase(<string>,<string>)
傳回布林值。
startWithIgnoreCase("rowing is great", "RO")
傳回true。
substr substr
傳回開始索引和結束索引之間的字串運算式的子字串。 如果未定義結束索引,則它介於開始索引和結束索引之間。
substr(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
| beginindex | 整數 |
| endIndex | 整數 |
substr(<string>,<beginIndex>)
substr(<string>,<beginIndex>,<endIndex>)
傳回字串。
substr("Hello World",6)
傳回「World」。
substr("Hello World", 0, 5)
傳回「Hello」。
trim trim
移除開始和結束空格。
trim(<parameters>)| table 0-row-2 1-row-2 | |
|---|---|
| 參數 | 類型 |
| 字串 | 字串 |
trim(<string>)
傳回字串。
trim(" Hello ")
傳回「Hello」。
upper upper
傳回引數的大寫版本。
upper(<parameters>)upper(<string>)
傳回字串。
upper("b")
傳回「B」。
UUID uuid
產生隨機UUID (通用唯一識別碼)。
uuid()uuid()
傳回字串。
uuid()
傳回「79e70b7f-8a85-400b-97a1-9f9826121553」。
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all string functions available in AJO journey expressions, covering text search, comparison, transformation, extraction, validation, replacement, splitting, and unique identifier generation.
Intents:
- Concatenate two or more strings using
concat - Search for a substring within a string (case-sensitive or case-insensitive) using
containorcontainIgnoreCase - Compare two strings while ignoring case using
equalIgnoreCaseornotEqualIgnoreCase - Check whether a string starts or ends with a specific prefix or suffix using
startWith,endWith, and their case-insensitive variants - Extract a substring by index positions using
substr - Replace the first or all occurrences of a pattern in a string using
replaceorreplaceAll - Split a string into a list of tokens by a separator using
split - Generate a random UUID for unique identifier needs using
uuid - Check if a string is empty or non-empty using
isEmptyorisNotEmpty
Glossary:
- RegExp: A regular expression pattern used as the target parameter in
replace,replaceAll, andmatchRegExp— special characters must be escaped with\\ - UUID: Universal Unique IDentifier — a randomly generated string identifier returned by
uuid() - substr: Extracts a portion of a string by specifying a start index and optional end index (zero-based)
Guardrails:
- The
targetparameter inreplaceandreplaceAllis treated as a RegExp; special characters (e.g.,|,.) must be escaped with\\ replacereplaces only the first matching occurrence; usereplaceAllto replace every occurrenceisEmptyreturns false for null values (not true); null is not considered an empty stringindexOfandlastIndexOfreturn -1 when no match is found- String index positions are zero-based (the first character is at position 0)
Terminology:
- Canonical name: String functions — Acronym: none — variants: text functions, string manipulation functions
- Synonyms: “contain” = “substring check”; “split” = “tokenize string”; “trim” = “strip whitespace”
- Do not confuse: “replace” (first occurrence only) ≠ “replaceAll” (all occurrences)
- Do not confuse: “indexOf” (first occurrence position) ≠ “lastIndexOf” (last occurrence position)
- Do not confuse: “isEmpty” (true only for zero-length string) ≠ null check (isEmpty returns false for null)
- Do not confuse: “equalIgnoreCase” (returns true when equal ignoring case) ≠ “notEqualIgnoreCase” (returns true when different ignoring case)
FAQ:
- Q: How do I check if a string contains a substring regardless of case? — Use
containIgnoreCase("myString", "searchTerm"), which returns true if the search term is found in any case. - Q: What is the difference between
replaceandreplaceAll? —replacesubstitutes only the first matching occurrence;replaceAllsubstitutes every occurrence in the string. - Q: Why do I need to escape the
|character inreplace? — The target parameter is treated as a regular expression;|is a special RegExp character and must be escaped as\\|to be treated as a literal pipe. - Q: Does
isEmptyreturn true for null? — No,isEmptyreturns false for null; it only returns true for a zero-length string"". - Q: How do I extract the major version number from a version string like “20.45.2.3434”? — Use
getListItem(split(@event{event.appVersion}, "\\."), 0)to split by dot and retrieve the first element. - Q: How do I generate a unique identifier in a journey expression? — Use
uuid(), which returns a randomly generated UUID string with no parameters required.