tags:

views:

1366

answers:

1

All,

I have the challenge in AppleScript to manipulate a string as follows:

  • Base string is an email recipient display name, say "First Last ([email protected])"
  • I'd now like to "trim" the display name to remove the actual email address in the brackets
  • The desired result should be "First Last" - so also the space in front of the first bracket needs to be removed.

What is the best and most efficient way to do this in AppleScript? Thanks.

Cheers,

-Sven

A: 
set theSample to "First Last ([email protected])"

return trimEmailAddress(theSample)
-->Result: "First Last"

on trimEmailAddress(sourceAddress)
    set AppleScript's text item delimiters to {" ("}
    set addressParts to (every text item in sourceAddress) as list
    set AppleScript's text item delimiters to ""
    set nameOnly to item 1 of addressParts

    return nameOnly
end trimEmailAddress
Philip Regan