안녕하세요,
수신 이메일의 본문을 스캔하는 자동화를 실행하고 있습니다. 이메일 본문은 문자열 변수에 저장됩니다.
이메일 본문은 기본적으로 목록에 있는 키-값 쌍입니다. 예:
Key1:Value1
Key2:Value2
Key3:Value3
제 예시에서 키는 “receiver” 또는 "reference"와 같은 단어입니다.
문제는 이 프로세스가 사용자 작업(이메일 발신자)에 의해 트리거된다는 점입니다. 프로세스의 안정성을 높이기 위해 대소문자 문제를 없애고 싶습니다.
이메일 본문 텍스트에 split 함수를 적용해 값을 별도의 변수에 저장하고 있습니다.
예: Split((split(strMailBody.Trim,<str Key 1>>)(1).ToString),<str Key 2>)(0).ToString
결과: key1 뒤에서 시작해 key2 앞에서 끝나는 문자열
이제 문제가 있습니다.
split 함수를 제대로 실행하려면 검색 문자열의 대소문자를 지정해야 합니다. 예를 들어 "reference"라고 해야 합니다. 요청자가 "Reference"나 "REFERENCE"라고 입력하면 대소문자를 구분하기 때문에 split 함수가 작동하지 않는 것 같습니다.
임시방편으로 같은 키워드의 표기 방식이 다른 경우를 찾도록 여러 개의 if 문을 설정하고 문자열을 목표 형식에 맞게 수정했습니다. 지금까지는 잘 작동하지만 그다지 우아한 방법은 아닙니다. 가능한 모든 표기 방식의 키워드를 목록에 넣고 반복문을 사용할 수도 있다는 것은 알고 있지만, 그러더라도 각 키워드를 개별적으로 확인하는 if 문이 필요하다는 점은 달라지지 않습니다.
이 문제를 해결할 더 똑똑한 방법(모범 사례)이 있는지 궁금합니다.
Hi @SenorChang
Convert the mail body and keys to lowercase before using the split function. This removes the case sensitivity issue.
Example expression:
Split(LCase(strMailBody), “receiver:”)(1).Split(“reference:”)(0).Trim
This will work even if the keys in the email body are written as Receiver, RECEIVER, or receiver.
Happy Automation
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.
I dont get it how this would translate to code.
How can I make sure that the value of every line is stored in a separate variable? Since the mailbody is a simple string and not a list or DT.
@SenorChang
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.
Happy Automation
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.
Hi @SenorChang
Glad to hear your problem is solved and you are loving the forum 
Could you please share the solution?
And then mark that solution post as solution. This would help others users if they face similar issue.
Regards
Sonali
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.