You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Automate中替换字符串第3次出现的指定字符方法咨询

Solution for Replacing the 3rd Occurrence of " | " in Power Automate

Since you're working in Power Automate (given the "Apply to each" mention), here's a reliable way to target and replace the 3rd occurrence of | with | Product: in each string of your array:

Step-by-Step Expression

Inside your "Apply to each" loop, use this expression for the current item (item()):

join(
  take(split(item(), ' | '), 3),
  ' | '
)
& ' | Product: ' &
join(
  skip(split(item(), ' | '), 3),
  ' | '
)

How This Works

Let’s break down the logic using your first example string:
"Periods: 01.01.2023 - 01.02.2023 | Code: 111 | Code2: 1111 | product-name"

  1. split(item(), ' | ') splits the string into an array:
    ["Periods: 01.01.2023 - 01.02.2023", "Code: 111", "Code2: 1111", "product-name"]
    
  2. take(..., 3) grabs the first 3 elements, then join(..., ' | ') reconstructs the first part of the string:
    "Periods: 01.01.2023 - 01.02.2023 | Code: 111 | Code2: 1111"
    
  3. We append ' | Product: ' to add the new field label.
  4. skip(..., 3) takes everything from the 4th element onward (your product name), and join puts it back together (this handles edge cases where product names might contain | too, even if your example doesn't have this scenario).

Result for Your Example

After applying the expression, your first string becomes:
"Periods: 01.01.2023 - 01.02.2023 | Code: 111 | Code2: 1111 | Product: product-name"

This method avoids the pitfalls of trying to count occurrences directly (which can fail if earlier parts of the string have unexpected | characters) and works consistently for all items in your array.

内容的提问来源于stack exchange,提问作者Artemy Panin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 16:10:27