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

Roman_to_Arab

Syntaxe

roman_to_arab(theString)
Convertit un nombre en chiffres romains en chiffres arabes. Le paramètre est au format texte, le résultat est au format nombre.
Adaptation d'un programme en basic de Donald Alcock.

Exemple

roman_to_arab("MCMLIX")
---> 1959

Script

on Roman_to_Arab(romain) -- Caractères autorisés : M, D, C, L, X, V, I
--===== TABLE D'ETATS =====
-- LES {"z"} CORRESPONDENT A DES IMPOSSIBILITéS Ex: DDD AFFICHE LE MSG D'ERREUR
set list_rom1 to {"I", "V", "X", "L", "C", "D", "M"}
set I_list to {{1, 11}, {1, 11}, {1, 11}, {1, 11}, {1, 11}, {1, 11}, {1, 11}, {1, 8}, {1, 11}, {1, 11}, {1, 8}}
set V_list to {{5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 7}, {5, 8}, {"z"}, {5, 8}, {5, 8}, {3, 0}}
set X_list to {{10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 6}, {"z"}, {"z"}, {10, 10}, {10, 6}, {8, 0}}
set L_list to {{50, 5}, {50, 5}, {50, 5}, {50, 5}, {50, 6}, {"z"}, {"z"}, {"z"}, {50, 6}, {30, 7}, {"z"}}
set C_list to {{100, 9}, {100, 9}, {100, 9}, {100, 4}, {"z"}, {"z"}, {"z"}, {"z"}, {100, 4}, {80, 7}, {"z"}}
set D_list to {{500, 3}, {500, 3}, {"z"}, {"z"}, {"z"}, {"z"}, {"z"}, {"z"}, {300, 5}, {"z"}, {"z"}}
set M_list to {{1000, 2}, {1000, 2}, {"z"}, {"z"}, {"z"}, {"z"}, {"z"}, {"z"}, {800, 5}, {"z"}, {"z"}}
set list_list to {I_list, V_list, X_list, L_list, C_list, D_list, M_list}
--====================
set arabe to 0
set compt to 1 -- 1er CHIFFRE ROMAIN LU <=> 1er ITEM DE LA LISTE [ EX: {5, 7} de V_list ]
try -- CORRESPONDANCE DES CHARS ROMAINS DANS LA TABLE D'ETATS
repeat with i in (romain)
set istr to i as string
set temp to item 1 of (item compt of num_to_Item(item_to_num(istr, list_rom1), list_list))
set compt to item 2 of (item compt of num_to_Item(item_to_num(istr, list_rom1), list_list))
set arabe to (arabe + temp)
end repeat
return arabe
on error msg number num
return "Format incorrect."
end try
end Roman_to_Arab

on item_to_num(x, y)
return offset of x in y as string
end item_to_num

on num_to_Item(x, y)
return item x of y
end num_to_Item

Remarque

Les listes de variables permettent de simuler un tableau à 2 dimensions.

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