51 routines :

*AppleScriptsVanilla*
ascii_to_HTML
Average
Calculator
Calendar
Count_item
cut_text
days_week
EAN13
Encrypt-Decrypt
FactPremier
French_Vanilla_Dotted_Date
French_Vanilla_Dotted_Date2
Hexa_to_Bin
Last_month
list_erase
list_insert
list_replace
ListeDiviseurs
ListePremiers
Minuscule
NombreLong
NombreLong2
NomExtension
num_item
num_month
num_month2
num_week
number_format
number_format2
Paques
PGCD
PGCD2
reverse_string
Roman_to_Arab
round_decimal
search_email
search_replace
search_URL
SepNbre
SepNbre2
snip_text
stat
TauxPermut
TauxTransform
the_left
the_right
TriBulle
TriLineaire
week_and_year
XOR
ZeroDouble

search_email

Syntaxe

SearchEmail(texte)
Extrait les emails d'une chaîne de caractères sous forme de liste. Le pramètre et le résultat sont au format texte.

Exemple

SearchEmail("wanted 3000 $ averel@dalton.org and joe@dalton.org dead or alive")
--->{"averel@dalton.org", "joe@dalton.org"}

Script

on SearchEmail(theString)
set listEmail to ""
set the theString to " " & theString & " "
repeat until the length of theString is 0
set Arob to offset of "@" in theString
if Arob = 0 then exit repeat
set debutToArob to (characters Arob thru 1 of theString as string)
set ArobTodebut to ((reverse of (every character of debutToArob as list)) as string)
set espace to offset of " " in ArobTodebut
set debutMail to Arob - espace + 2
set fin to the length of theString
set temp to characters debutMail thru fin of theString as string
set finmail to (offset of " " in temp) - 2
set mail to (characters debutMail thru (debutMail + finmail)) of theString as string
set listEmail to (listEmail & mail as list)
set theString to characters (debutMail + finmail + 1) thru fin of theString as string
end repeat
return listEmail
end SearchEmail

Remarque

Le principe consiste à utiliser offset pour rechercher l'arobase puis à partir de là, dans un 1er temps, remonter la chaïne jusqu'à un " " et dans un 2ème temps la descendre jusqu'à un espace pour avoir l'email au complet. Reverse permet de pouvoir utiliser offset dans le 2ème temps descendant qui devient donc ascendant (relire plusieurs fois ;-) L'ajout d'une espace " " en début et en fin de chaîne (set the theString to " " & theString & " "), évite que la commande offset ne renvoie un message d'erreur à la fin de l'éxécution de la routine.

Site scripté avec HyperCard ©1987-1998 Apple Computer, Inc.
Mise à jour le 19/01/10 à 08:45:57