4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Power Automateで2種以上の文字列で文字列分割を行う

Posted at

はじめに

Power Appsで、2つの文字列で、対象となる文字列を分割する方法を以前の投稿で紹介しました。(こちら)
今回はそのPower Automate版です。

全体としてはこのような形です。短く3ステップで。
image.png

やってみる

SplitしてSplit

最初のSelectアクションで、Split2回を一度に終わらせます。
image.png
このアクションの結果、Power Appsで作ったときと同じような入れ子のjsonが生成されます。(Hello/World/!!の例)

splitoutput.json
[
  {
    "value": [
      "Hell",
      ""
    ]
  },
  {
    "value": [
      "W",
      "rld"
    ]
  },
  {
    "value": [
      "!!"
    ]
  }
]

こっから、あとはvalueの中をすべて1つの配列に入れれば完成です。(ここがちょっと難しい)

深い階層の特定要素の一覧をつくる

こんな時はxpathによる値取得が最適です。
前のアクションの結果を、xml化できるようにroot要素を追加します。(ここはComposeアクション)

続いて、Selectアクションでは、xmlをつくり、xpathで値を取得します。

'//*/value'

/text()を後ろにつけると、空白がそぎ落とされるので、ここではvalueで止めています。
こうすると、結果Selectアクションのitem()はバイナリになります。なので、Mapではjson()をつかって文字列に戻しています。

image.png

結果はこちら
image.png

もし結果得られる配列をkey:valueの形式にしたいのであれば、Mapの中を

json(item())?['value'] --> json(item())

と置き換えればよいです。
image.png

おわり

Power Appsのように1アクションですべてをまかなうような記述は見つけられませんでしたが、比較的少ないアクションで文字列を2つのdelimiterで分割できました。
毎回Power AutomateでSelectアクションの万能さに驚かされます。 ご質問があればTwitterまで!

サンプルはこちら
https://github.com/mofumofu-dance/PowerApps365/blob/master/Samples/SplitTextBy2Delimiters.zip

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?