And here’s a third, using TextEdit app (fairly universally available) as your search engine. This will scale well for performance if you only need to set up the document once, and query it many times.
property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}
repeat with n from 1 to count Codes
set allMnemonics to allMnemonics & item n of Codes & ", " & item n of Mnemonics & return
tell application "TextEdit"
if not (exists document "Mnemonics") then
make new document with properties {name:"Mnemonics"}
set text of document "Mnemonics" to allMnemonics
tell application "TextEdit"
set theParagraphs to every paragraph of document "Mnemonics" where it begins with aCode
return ((characters 7 thru -2 of item 1 of theParagraphs) as text)
And here’s a fourth, using Excel app as your calculation engine. This will scale well for very large data sets, again if you only have to set up the document once
property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}
on setupExcelDoc()
tell application "Microsoft Excel"
if not (exists document "Mnemonics") then
set theDoc to make new document with properties {name:"Mnemonics"}
else
set theDoc to document "Mnemonics"
end if
tell worksheet 1 of theDoc
repeat with n from 1 to count Codes
set value of cell 1 of row n to item n of Codes
set value of cell 2 of row n to item n of Mnemonics
end repeat
end tell
end tell
end setupExcelDoc
on MnemonicOf(aCode)
set numRows to count Codes
tell application "Microsoft Excel"
set foundRange to find range ("A1:A" & (numRows as text)) what aCode
set foundRow to first row index of foundRange
return value of cell 2 of row foundRow of worksheet 1 of document "Mnemonics"
end tell
end MnemonicOf
setupExcelDoc()
MnemonicOf("9470")