Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get all keys as single string from TDictionary class

is there any smarter way ( with less code) to go get all keys from a TDictionary as a single string, comma separated

var
  FDicList : TDictionary <String, Integer>;
  KeyStrList: TStringlist;
  KeyName: string;
begin

  /// result as comma text
  KeyStrList := TStringlist.Create;
  try
    for KeyName in FDicList.Keys do
      KeyStrList.Add(KeyName);

    All_keys_as_string := KeyStrList.CommaText;
  finally
    KeyStrList.Free;
  end; 

end;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As long as the keys don’t contain a comma itself you can just write:

All_keys_as_string := string.Join(',', FDicList.Keys.ToArray);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading