I have an automation running which scans the mail body of an incoming email. The mailbody is stored in a string variable.
The mailbody is basically a key value pair in a list. E.g.:
Key1:Value1
Key2:Value2
Key3:Value3
In my example the key would be something like “receiver” or “reference”.
The challenge is that the process is triggered by user action (the sender of the mail). As I am looking to make the process more robust I want to get rid of casing issues.
I store the values in separate variables which are generated via split function of the mailbody text.
Example: Split((split(strMailBody.Trim,<str Key 1>>)(1).ToString),<str Key 2>)(0).ToString
Result: String beginning after key1 and finishing before key2
Now here comes the problem:
To perform the split function properly I need to give the casing of the search string, e.g. “reference”. If the requestor writes the word “Reference” or even “REFERENCE” the split function does not work because I believe it is case sensitive.
What I did as workaround is to set multiple if statements to look for the different spelling of a same keyword and manipulate the string to target format. This works fine so far but it is not that elegant. I know that I could also loop through a list with all the keywords with all potential spelling but this would not eliminate the fact that I need an if statement to check each keyword separately.
I would be interested if there would be a smarter solution for this issue (best practice)?
This was exactly my first go to but the problem is that I don’t want the values to be lower case (it should have the original casing). The values are typed into a web app.
You can convert the text to lowercase only for comparison, then extract the original text from the mail body without changing its casing. Use .ToLower on both the key and the mail body for the search, but when retrieving the value, keep the original text intact.
Sorry but I don’t understand it. If I want to retrieve the value I have to define the exact casing of the string which I overwrite when I apply the lower case. When I do lower case for comparison then I know that the key is contained in the string but I have no start and end point where I cut the section for my variables.
BTW: Problem solved without regex (it is overpowered for this case) but it was a good inspiration for me. Thanks so much for contribution. Loving this forum.
I added a unique separator (“;”) to the string. This helped me to separate the lines.
Then I did a split function and split the string to an array.
After that I did another split with “:” as separator and only get the right side of the string.
That way I can easily generate my values and I don’t have casing issues in the future. In fact, I don’t even rely on the key because I just read the value.
Edit: I even improved the mechanism further. I do check the key to assign the value of key:value pair to the right variable. Now I am even independent of the order of the key:value pairs in the mailbody.