文字列関数 string-functions
文字列関数を使用すると、ジャーニー式内のテキスト値を操作および操作できます。 これらの機能は、カスタマージャーニーでのテキスト処理、検証、変換および分析に不可欠です。
次の必要がある場合は、文字列関数を使用します。
- 複数のテキスト値の連結および結合(concat)
- 特定のテキストパターンまたは部分文字列(contain、containIgnoreCase、indexOf、lastIndexOf、matchRegExp)を検索します
- 大文字と小文字を区別する、または大文字と小文字を区別しない一致する文字列を比較します(equalIgnoreCase, notEqualIgnoreCase)
- 文字列の開始と終了を確認します(startWith、startWithIgnoreCase、endWith、endWithIgnoreCase)
- 部分文字列操作を使用してテキストの一部を抽出する(substr)
- テキストを大文字または小文字に変換(upper、lower、trim)
- 文字列が空であるか、特定の値(isEmpty、isNotEmpty)を含んでいるかを確認します
- テキストパターンを新しい値に置き換えます(replace, replaceAll)
- さらに処理するために文字列を配列に分割(split)
- 文字列の長さを取得(length)するか、一意の識別子を生成(uuid)します
文字列関数は、包括的なテキスト操作機能を提供し、ジャーニー式のテキストコンテンツに基づく高度なデータ処理と条件付きロジックを可能にします。
concat concat
2 つの文字列パラメーターまたは 1 つの文字列リストを連結します。
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
1 番目の引数文字列に 2 番目の引数文字列が含まれているかどうかを確認します。
contain(<parameters>)- 文字列
contain(<string>,<string>)
ブール値を返します。
contain("rowing is great", "great")
true を返します。
containIgnoreCase containIgnoreCase
2 番目の引数文字列が最初の引数文字列に含まれているかどうかを、大文字と小文字の区別をせずに確認します。
containIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| 文字列 | 文字列 |
| 検索文字列 | 文字列 |
containIgnoreCase(<string>,<string>)
ブール値を返します。
containIgnoreCase("rowing is great", "GREAT")
true を返します。
endWith endWith
2 番目のパラメーターが最初のパラメーターの末尾にある場合、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
最初の引数文字列が特定の文字列(2 番目の引数文字列)で終わっているかどうかを、大文字と小文字の区別をせずに確認します。
endWithIgnoreCase(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| 文字列 | 文字列 |
| 末尾の文字列 | 文字列 |
endWithIgnoreCase(<string>,<string>)
ブール値を返します。
endWithIgnoreCase("rowing is great", "AT")
true を返します。
equalIgnoreCase equalIgnoreCase
大文字と小文字を区別せずに、最初の引数文字列と 2 番目の引数文字列を比較します。
equalIgnoreCase(<parameters>)- 文字列
equalIgnoreCase(<string>,<string>)
ブール値を返します。
equalIgnoreCase("rowing is great", "rowing is GREAT")
true を返します。
indexOf indexOf
2 番目のパラメーターが最初に現れる(最初の引数内の)位置を返します。一致するものがない場合は「-1」を返します。
indexOf(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| string | String |
| 指定値 | 文字列 |
indexOf(<string>,<string>)
整数を返します。
indexOf("Hello", "l")
2 を返します。
説明:
「Hello」で「l」が最初に出現するのは位置 2 です。
isEmpty isEmpty
パラメーター内の文字列に文字が含まれていない場合は true を返します。
isEmpty(<parameters>)- 文字列
isEmpty(<string>)
ブール値を返します。
isEmpty("")
true を返します。
isEmpty("Hello World")
false を返します。
isNotEmpty isNotEmpty
パラメーター内の文字列が空でない場合、true を返します。
isNotEmpty(<parameters>)- 文字列
isNotEmpty(<string>)
ブール値を返します。
isNotEmpty("")
false を返します。
isNotEmpty("hello")
true を返します。
lastIndexOf lastIndexOf
2 番目のパラメータが最後に現れる(最初の引数内の)位置を返します。一致するものがない場合は -1 を返します。
lastIndexOf(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| string | String |
| 指定値 | 文字列 |
lastIndexOf(<string>,<string>)
整数を返します。
lastIndexOf("Hello", "l")
3 を返します。
説明:
「Hello」で「l」が最後に出現するのは位置 3 です。
length length
パラメーター内の文字列式の文字数を返します。
length(<parameters>)- 文字列
length(<string>)
整数を返します。
length("Hello World")
11 を返します。
lower lower
パラメーターを小文字にしたものを返します。
lower(<parameter>)- 文字列
lower(<string>)
文字列を返します。
lower("A")
「a」を返します。
matchRegExp matchRegExp
1 番目のパラメーターの文字列が 2 番目のパラメーターの正規表現と一致する場合、true を返します。 詳しくは、このページを参照してください。
matchRegExp(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| 文字列 | 文字列 |
| 正規表現 | 文字列 |
matchRegExp(<string>,<string>)
ブール値を返します。
matchRegExp("12345", "\\d+")
true を返します。
notEqualIgnoreCase notEqualIgnoreCase
最初の引数の文字列と 2 番目の引数の文字列が異なるかどうかを、大文字と小文字の区別を無視して確認します。
notEqualIgnoreCase(<parameters>)- 文字列
notEqualIgnoreCase(<string>,<string>)
ブール値を返します。
notEqualIgnoreCase(@event{iOSPushPermissionAllowed.device.model}, "iPad")replace replace
ターゲット文字列に一致する最初の出現箇所を、ベース文字列内の置換文字列で置き換えます。
置換は、文字列の先頭から末尾に向かって行われます。例えば、文字列「aaa」の「aa」を「b」に置き換えると、「ab」ではなく「ba」になります。
replace(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| パラメーター | タイプ |
| base(ベース文字列) | 文字列 |
| target(ターゲット文字列) | 文字列(RegExp) |
| replacement(置換文字列) | 文字列 |
replace(<base>,<target>,<replacement>)
文字列を返します。
replace("Hello World", "l", "x")
「Hexlo World」を返します。
正規表現の例:
ターゲットパラメーターは 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」に置き換えると、「ab」ではなく「ba」になります。
replaceAll(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| パラメーター | タイプ |
| base(ベース文字列) | 文字列 |
| target(ターゲット文字列) | 文字列(RegExp) |
| replacement(置換文字列) | 文字列 |
replaceAll(<baseString>,<sourceString>,<replacementString>)
文字列を返します。
replaceAll("Hello World", "l", "x")
「Hexxo Worxd」を返します。
ターゲットパラメーターは RegExp なので、置き換える文字列に応じて、一部の文字をエスケープする必要が生じる場合があります。replace 関数の例を参照してください。
split split
1 番目の引数文字列を区切り記号列(2 番目の引数文字列:正規表現を指定可能)で分割して、文字列(トークン)のリストを作成します。
split(<parameters>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| パラメーター | タイプ |
| 入力文字列 | 文字列 |
| 区切り記号列 | 文字列 |
split(<input string>, <separator string>)
文字列リストを返します。
split("A_B_C", "_")
["A","B","C"] を返します。
イベントフィールド「event.appVersion」の値が「20.45.2.3434」の場合の例
split(@event{event.appVersion}, "\\.")
["20", "45", "2", "3434"] を返します
startWith startWith
2 番目のパラメーターが最初のパラメーターの接頭辞にある場合は、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
大文字と小文字を区別しない場合に 2 番目のパラメーターが最初のパラメーターの接頭辞としてある場合は、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 | 整数 |
| 終了インデックス | 整数 |
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(Universal Unique IDentifier)を生成します。
uuid()uuid()
文字列を返します。
uuid()
「79e70b7f-8a85-400b-97a1-9f9826121553」を返します。