有沒有更聰明的方法(用更少的代碼)從 TDictionary 中獲取所有鍵作為單個字串,逗號分隔
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;
uj5u.com熱心網友回復:
只要鍵本身不包含逗號,您就可以撰寫:
All_keys_as_string := string.Join(',', FDicList.Keys.ToArray);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/438615.html
標籤:德尔福
