メール本文の内容を特定の記号(|)でKeyとvalueに分けてディクショナリ変数に格納したいです。

お世話になっております。

メールの本文内の情報を辞書型変数として格納する方法はないかの問合せです。

今、メールの本文の内容に沿って帳票出力をしていくロボットを作成しています。

メール本文は『|』で項目と値を分けるように記載されています。
ディクショナリ変数でこの文字列の行ごとにそれぞれ
[Key]|[Value]
として格納することは出来るのでしょうか?

以下、読取たいメール本文の記載例を掲載します。

<↓本文例↓>
好きな食べ物|カレー
嫌いな食べ物|パクチー
アレルギー|小麦粉
<↑本文例↑>

よろしくお願いいたします。

Hi @23fa3ada9efcafb23f0963434

Use the below syntax:

=> Initialize an Dictionary variable like below at start of the flow:

dict = New Dictionary(Of String, String)

dict is of DataType System.Collections.Generic.Dictionary(System.String, System.String)

=> Use Get Outlook Mail Messages to read the Email and store the output in a variable say MailMessages.

=> Use For Each loop to iterate through MailMessages and inside the loop use the below assign syntax.

dict = currentMailMessage.Body.Split({vbCrLf}, StringSplitOptions.RemoveEmptyEntries).
                 Select(Function(line) line.Split({"|"}, StringSplitOptions.None)).
                 ToDictionary(Function(parts) parts(0).Trim(), Function(parts) If(parts.Length > 1, parts(1).Trim(), String.Empty))

Email Input:

Dictionary output:
image

Below is the sample workflow attached for your reference
Sequence24.xaml (10.4 KB)

Regards

こんにちは

可能ですが、もう少し入力文字列を明確にした方が良いかもしれません。
たとえば上記のDictionary化したい文字列以外に文字列があるか等

以下は正規表現で必要な項目のみ抽出する例です。

mc= System.Text.RegularExpressions.Regex.Matches(strMailBody,"(?<KEY>.*?)\|(?<VALUE>.*)")
dicy =mc.Cast(OF System.Text.RegularExpressions.Match).ToDictionary(Function(m) m.Groups("KEY").Value,Function(m) m.Groups("VALUE").Value.Trim)

Sample
Sample20240803-1a.zip (2.8 KB)