用基本字串中的替換字串替換與目標字串匹配的第一個匹配項。
替換從字串的開頭到結尾,例如,在字串"aaa"中將"aa"替換為"b"將導致"ba"而不是"ab"。
字串
replace(<parameters>)
參數 | 類型 |
---|---|
基礎 | 字串 |
Target | 字串(RegExp) |
替換 | 字串 |
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}, '')