I have extracted a .txt file from an outlook email, and read the file. I now need to pull the numbers (which change daily) and insert them into an excel file. I have a general understanding of how to input them into the excel file, but I am unsure of how to pull the dynamic numbers each day. Any help would be appreciated.
Assuming the format stays the same, and you’re only looking for the one value,you could assign the variables using Regex. By importing System.Text.RegularExpression, you can then assign a variable using this
grossPremium = Regex.Match(txtFileAsString, “(?<=Gross Premium: $)[\d,]+”).Value
This looks for the Gross Premium string pattern, and extracts the number that follows it (including the comma), regardless of what that number is or how long that number is…
Note: There should be a backslash before the $ within that regular expression
Hi
Welcome to uipath community
If this is the input string
Then use a assign activity like this
str_GrossPremium = System.Text.RegularExpressions.Regex.Match(str_input,”(?<=Gross Premium:).+”).ToString
And another assign activity like
str_Commission = System.Text.RegularExpressions.Regex.Match(str_input,”(?<=Commission:).+”).ToString
Then final assign activity with this
str_NetPremium = System.Text.RegularExpressions.Regex.Match(str_input,”(?<=Net Premium:).+”).ToString
—now inspite is this
Use a BUILD DATATABLE ACTIVITY and create three columns with name
GrossPremium,Commision,NetPremium
All of type string and get the output with a variable of type datatable named dt
—the use CLEAR DATATABLE ACTIVITY and mention the datatable as dt
—now use these three assign activity as mentioned above with those expressions
—and followed by that use ADD DATAROW activity and in the ArrayRow property mention as
{str_GrossPremium, str_Commission, str_NetPremium} and in the datatable property mention as dt
This will add these records to datatable dt
Hope this would help you resolve this
Cheers @Ltanksley
Awesome, that helped with my initial quesrion. However, I need to pull one more number to go into the same datatable.
All numbers on this row are dynamic and change daily. Is there a way to use regex to capture this number still of would OCR be a better option.
Thanks all for your time.
Fine
This expression would help you get that highlighted number
str_matches = System.Text.RegularExpressions.Regex.Matches(stringvariable.ToString,”[^ ][0-9]+”)
Where str_matches is a variable of type
System.Collections.Generic.Ienumerable(System.Text.RegularExpressions.Regex.Match)
—then use a FOR EACH activity and pass the above variable as input and change the type argument as System.Text.RegularExpressions.Regex.Match in the property panel of for each activity
—inside the loop use a WRITELINE activity and mention like this item.ToString
Hope this would help you
Cheers @Ltanksley
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.