Extract Content from Email Body

Hi, i’m trying to extract information from the email body. how can we do that?



USD/SGD rate : 1.343200000
MYR/SGD rate : 0.325821710
JPY /SGD rate : 0.012365478
CNY/SGD rate : 0.206328725

Desired Output is extract them to datatable, example;
Currency Rate
USD/SGD 1.3432
MYR/SGD 0.325821710

Hello @jerry.kohzl

You need a 2 step process.
Step 1 : Split the body content on the basis of the new line
example :: extractedData.Split(Environment.NewLine.ToArray,StringSplitOptions.None)
where extractedData is your body content string.

Step 2 : This will give you a String which you loop through and further split on the basis of “:”.

This same scenario is present in the developer academy assignment regarding the “Client security hash” assignment.

Hope this helps you.

thanks, i’m able to split the lines. so in the array i only need 4-7. i’m trying to use generate datatable to the data, but what should i indicate array range in the input?

i.e. my variable is Arr(4) to Arr(7).

Hello @jerry.kohzl,

2 points.

  1. If the body will only contain those 4 lines then yes you can use the index.
  2. Before we make the 2nd split using the “:”. We can make the solution more generic by first checking whether the string contains something like "rate : ". if the string contains this section then you are assured to always get a rate value and all other lines can be skipped over.
    Using this approach is more appreciated since it will work even in case the number of rates received are variable in nature.

Hi @jerry.kohzl Suppose you splitted the text in SplittedText variable which is a string of array. Now you need 4th to 7th index. You can get those using SplittedText(4), SplittedText(5), SplittedText(6), SplittedText(7)


I would use regex instead of trying to split the strings. I believe it much eachier :slight_smile:

1 Like