What is the simplest way to work with associative strings (key/values)?
delphi
Solution
Yes, assignment can be done this way instead, avoiding manual string concatenation:
MyStringList.Values[Key1] := Value1;
Problem
I have a lot of constants that are somehow related, at some point I need to pair them, something like this: ``` const key1 = '1'; key2 = '2'; key3 = '3'; value1 = 'a'; value2 = 'b'; value3 = 'c'; ``` I want to avoid doing: ``` if MyValue = key1 then Result := value1; ``` I know how to do it with string lists using: ``` MyStringList.Add(key1 + '=' + value1); Result := MyStringList.Values[key1]; ``` But, is there any simpler way to do this?