acantor Posted January 14, 2011 Report Share Posted January 14, 2011 I am scripting a macro to extract an email address from a text variable called, say, %RawText%. The content of the variable may take several forms, e.g., S. Smith [s.smith@xyz123.com] [s.smith@xyz123.com] s.smith@xyz123.com s.smith@xyz123.com on behalf of S. Smith I would be curious to learn how others would approach this so that only the email address remains. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 14, 2011 Report Share Posted January 14, 2011 Something like this is one approach. But I can think of several others. Just depends. Variable Set String %Raw Text%: Prompt Variable Set Integer %Position% to the position of "[" in %Raw Text% Variable Modify String %Raw Text%: Delete a substring starting at 1 and %Position% characters long If Variable %Position% Does not Equal "0" Variable Set Integer %Position% to the position of "]" in %Raw Text% Variable Modify Integer %Position%: Decrement Variable Modify String: Copy a substring in %Raw Text%, starting at 1 and %Position% characters long to %Raw Text% End If Variable Set Integer %Position% to the position of " on behalf of " in %Raw Text% If Variable %Position% Does not Equal "0" Variable Modify Integer %Position%: Decrement Variable Modify String: Copy a substring in %Raw Text%, starting at 1 and %Position% characters long to %Raw Text% End If Text Box Display: Result emails4Alan.mex Quote Link to comment Share on other sites More sharing options...
acantor Posted January 14, 2011 Author Report Share Posted January 14, 2011 Thank you, Cory, This is similar to what I came up with. I am wondering whether there is a way to split the string into two strings, one that includes everything to the left of @, the other everything to the right of @, manipulating the two strings, and then reassembling. This problem has just become more challenging: I found examples where there are two email addresses! Quote Link to comment Share on other sites More sharing options...
Cory Posted January 14, 2011 Report Share Posted January 14, 2011 Like I said it depends on the examples you have. Often I will approach it like my example and then other times I will do something with a lot more lines of code that works more universally. I have some pretty good sized macros that validate things like email addresses, file names, and SSNs and one could take the valid character routine and march forward and back from the @ with that. One simple way is to create a variable that contains every valid email character (don’t forget periods are valid) and compare character by character fore and aft to with an “If contains” test. This would work perfectly. However if you have a large number of email addresses to process it’s going to suck a lot more time. As for multiples they are usually separated by a character that is an invalid email character. Usually a semicolon. Wrap your cleaner script with a Split command on semicolon and repeat thru that resultant array until the variable is blank. Most of the time it will only happen once but it there are multiples it will handle them too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.