How to think about manipulating strings?

I'm very new to AA and am studying and setting myself puzzles. The first one is processing an incoming email. When I receive an email, I find the $Email From$ variable contains "John Smith smith@example.com". What I need is just the email address ... which means that I need to do some string processing.

As I study, I'm not yet sure how to approach this. It appears I may have options. For example, I see a command called "Run Script" that seems to allow me to run a JavaScript ... and in JavaScript I could achieve this processing quite easily.

Another possibility would be to use the "Replace Command" which seems to allow me to jump into RegEx programming (with all that entails).

A final possibility (at least as I see it) would be to try and create multiple commands using conditional logic at the command level by looking for "" and substringing based on that or using the whole string if not found.

My question/puzzle to the community is how should one go about thinking about puzzles like these?

Comments

  • Hi, I would be inclined to use the tools that are provided with AA. Namely use the String Operation Find command on $Email From$ with regex (\w+@\w+.\w+) - assign to the clipboard. This will give you the character position for the beginning of the email address (x@). Then use the String Operation Substring using the $Clipboard$ as the position character and leave the rest blank but assign it to a variable. That will give you the complete email address.
    However, there is a much simpler way! Use the String Operation Split command to give it the $Email From$ string delimited by " ". Start a loop command and check the List and select my-list-variable.
    Now do a variable operation within the loop, assigning $Email From$ to $my-list-variable$.
    After the loop, use the message box command to output $Email From$. You should have the email address.
    Hope that helps.

  • Meta discussion: I'm new to this forum. I found that when I entered "the less than symbol" and the "greater than symbol" they were eaten by the forum. This being a technical forum, I've got the suspicion that I'm going to do that lots. Do we have a suggestion for "escaping" these characters? Can this be made the default? I also seem to find that after making my post, I couldn't find a mechanism to go back and re-edit it. Is there a modification capability to existing posts?

  • @kolban said:
    Meta discussion: I'm new to this forum. I found that when I entered "the less than symbol" and the "greater than symbol" they were eaten by the forum. This being a technical forum, I've got the suspicion that I'm going to do that lots. Do we have a suggestion for "escaping" these characters? Can this be made the default? I also seem to find that after making my post, I couldn't find a mechanism to go back and re-edit it. Is there a modification capability to existing posts?

    You should be able tag your code in your posts, using the 'Code' item under the 'Format' button:

    So it looks <like this>

  • Is there an option to allow me to edit posts I have submitted? Experience tells me that I will make a post and then re-read it and want to make a change either to improve content or formatting.

  • one other way to get email id,
    use Before-After command, which falls under String Operation
    put $Email From$ in Source String,
    put < in Before Box, > in After Box
    and at bottom of String Operation Window, select desire variable from Assign the output to variable Drop-down box.

    you will have your answer in 1 command only. :)

  • The recipe I ended up using involved the String Operation called "Replace". This used some fancy RegEx manipulation to handle the case where we got either an email address by itself or an email address plus a name.

  • I'm fairly new to this. At this stage it looks like we will be calling little bits of script code to do string manipulations. I've got this working with VB Script but as we use Java I am trying to find out how to get that javascript to work. The AA string and date manipulation functions are rather basic compared to javascript - for instance it kept converting my dates to a number eg. My date string 2010-09-01 got changed to 2000 as it treated the date delimiters as minus signs. I got it working by building 2010-09-01x and using the replace function to change x to a zero length string. Also building that date using the $Day functions got 2010-9-1 and we needed the leading zeroes. Curently I think we should avoid anythig except very simple manipulations in the AA language and call javascript for anything else.

Sign In or Register to comment.