3

I have a set of abbreviated department names. I need to create a script which can map these abbreviations with their official titles. (For example: ADMIN → Administration)

In Java I could accomplish this using a HashMap.

public static void main() {
   HashMap hm = new HashMap(); // create hash map

   hm.put("ADMIN", "Administration");  // add elements to hashmap
   hm.put("RAD",   "Radiologist");
   hm.put("TECH",  "Technician");

   System.out.println("ADMIN is an abbreviation for " + hm.get("ADMIN"));
}

Is there an equivalent solution for this in AutoHotkey?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
  • 1
    https://autohotkey.com/board/topic/86523-list-and-dictionary-structures-in-autohotkey/ and others, just a google search away. – pvg Aug 17 '17 at 20:28

1 Answers1

3

You can implement key-value pairs using an Associative Array

An associative array is an object which contains a collection of unique keys and a collection of values, where each key is associated with one value. Keys can be strings, integers or objects, while values can be of any type. An associative array can be created as follows:

Array := {KeyA: ValueA, KeyB: ValueB, ..., KeyZ: ValueZ}

Here is an array which uses a job's shortened name (key) to find the full display name (value).

JobArray := {ADMIN:"Administration", TECH:"Technician", RAD:"Radiologist"}

; Check if key is present
if (JobArray.HasKey("ADMIN"))
    MsgBox, % "ADMIN is an abbreviation for " . JobArray["ADMIN"]
else
    MsgBox, % "No display name found"
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225