Re: Translate a code of 2 characters to a text
Re: Translate a code of 2 characters to a text
- Subject: Re: Translate a code of 2 characters to a text
- From: Matthew Stuckwisch <email@hidden>
- Date: Tue, 7 May 2002 07:11:31 -0500
I will receive a database wich contains about 9 fields. In one of these
fields, I have a 'code', like this:
CD, DVD, VHS, ...
I have about 80 'codes'. I must 'translate' this code in text like this:
CD = COMPACT DISC,
DVD = DIGITAL VERSATILE DISC
...
How can I 'translate' this code.
I wrote this (with 6 codes):
--
property ListOfMedia : {{"CD", "COMPACT DISC"}, ,
{"SA", "SUPER AUDIO"}, ,
{"MD", "MINI DISC"}, ,
{"MC", "MUSICASSETTE"}, ,
{"VH", "VIDEO"},,
{"DV", "DIGITAL VERSATILE DISC"}}
repeat with TheCounter from 1 to 6
if TheTypeOfMedia = item 1 of item TheCounter of ListOfMedia then
set TheTypeOfMedia to item 2 of item TheCounter of ListOfMedia
exit repeat
end if
end repeat
--
what about using a single list and a handler?
-----
property listOfMedia: {"CD","COMPACT DISC","SA", "SUPER AUDIO","MD",
"MINI DISC","MC", "MUSICASSETTE","VH", "VIDEO"
,"DV", "DIGITAL VERSATILE DISC"}
set typeOfMedia to what_is(typeOfMedia)
on what_is (abbrev)
repeat with i from 1 to 11 by 2
if (abbrev is item i of listOfMedia) then return (item (i+1) of
listOfMedia)
end repeat
end what_is
------
I think it could be done even quicker...
-----
on what_is(abbrev)
try
return item (((offset of (abbrev & " ") in "CD SA MD MC VH DV ") + 2)
/ 3) of {"COMPACT DISC", "SUPER AUDIO", "MINIDISC", "MINICASSETTE",
"VIDEO", "DIGITAL VERSATILE DISC"}
on error
return "NOT FOUND"
end try
end what_is
------
I'm on a Windoze right now so I can't test :( but I'm pretty sure it
should work. The reason I included spaces in the "CD SA MD MC VH DV " is
in case you get more abbreviations none of them could possibly overlay
(like, the last letter of one and the first letter of another would make a
separate abbreviation you'd be looking for).
Matthew Stuckwisch
[AIM/MSN]{GuifaSwimmer} | [Yahoo!]{SapphireTree} | [ICQ]{137477701}
[IRC]{guifa / G}(esperNET / irc.massinova.com)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.