字符串函数 string-functions
字符串函数允许您处理和处理历程表达式中的文本值。 这些功能对于客户历程中的文本处理、验证、转换和分析至关重要。
在需要时,请使用字符串函数:
- 连接和组合多个文本值(连接)
- 搜索特定的文本模式或子字符串(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")
返回真。
containIgnoreCase containIgnoreCase
检查第二个参数字符串是否包含在第一个参数字符串中,而不考虑大小写。
containIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 字符串 | 字符串 |
| 搜索字符串 | 字符串 |
containIgnoreCase(<string>,<string>)
返回布尔值。
containIgnoreCase("rowing is great", "GREAT")
返回真。
endWith endWith
如果第二个参数是第一个参数的后缀,则返回true。
endWith(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 字符串 | 字符串 |
| 后缀 | 字符串 |
endWith(<string>,<string>)
返回布尔值。
endWith("Hello World", "World")
返回真。
endWith("Hello World", "Hello")
返回假。
endWithIgnoreCase endWithIgnoreCase
检查第一个参数字符串是否以特定字符串(第二个参数字符串)结尾,而不考虑大小写。
endWithIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 字符串 | 字符串 |
| 后缀 | 字符串 |
endWithIgnoreCase(<string>,<string>)
返回布尔值。
endWithIgnoreCase("rowing is great", "AT")
返回真。
equalIgnoreCase equalIgnoreCase
将第一个参数字符串与第二个参数字符串进行比较,忽略大小写注意事项。
equalIgnoreCase(<parameters>)- 字符串
equalIgnoreCase(<string>,<string>)
返回布尔值。
equalIgnoreCase("rowing is great", "rowing is GREAT")
返回真。
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("")
返回真。
isEmpty("Hello World")
返回假。
isEmpty(<null>)
返回假。
isNotEmpty isNotEmpty
如果参数中的字符串不为空,则返回真。
isNotEmpty(<parameters>)- 字符串
isNotEmpty(<string>)
返回布尔值。
isNotEmpty("")
返回假。
isNotEmpty("hello")
返回真。
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+")
返回真。
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示例:
由于target参数是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”。
由于target参数是RegExp,因此根据要替换的字符串,您可能需要转义某些字符。 请参阅replace函数中的示例。
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")
返回真。
startWith("Hello World", "World")
返回假。
startWithIgnoreCase startWithIgnoreCase
如果第二个参数是第一个参数的前缀而不考虑大小写,则返回true。
startWithIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 字符串 | 字符串 |
| 前缀 | 字符串 |
startWithIgnoreCase(<string>,<string>)
返回布尔值。
startWithIgnoreCase("rowing is great", "RO")
返回真。
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.