Delphi 利用TDictionary 文本去重


本文整理自网络,侵删。

 
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Generics.Collections; {Delphi 2009 新增的泛型容器单元}
var
  Dictionary: TDictionary<string,string>;
//www.delphitop.com

procedure TForm1.Button1Click(Sender: TObject);
var
key:string;
pair: TPair<string,string>;
begin

//自动去重复
Dictionary.AddOrSetValue('key1', 'value1');
Dictionary.AddOrSetValue('key1', 'value2');

  {遍历看看}
{
 for pair in Dictionary.Keys do
 begin
   Memo1.Lines.Add(Dictionary[pair.Key]); //得到得结果都是不重复得
 end;  }


for key in Dictionary.Keys do
 begin
   Memo1.Lines.Add(key);  //得到得结果都是不重复得
 end;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Dictionary := TDictionary<string,string>.Create;

end;

end.

相关阅读 >>

Delphi静态和动态调用dll的实例

Delphi memo 滚动条 自动滚到最后一行

Delphi 三层架构简单例子(经测试成功)

Delphi tms web core messagedlg对话框 yes no

Delphi 查找并删除过期的日志目录

Delphi 操作“任务栏”

Delphi编写的android程序获取root权限实现(2015.4.15更新,支持android 4.4)

Delphi中使用可修改的常量

Delphi 调用cmd命令行并取得返回结果

Delphi listview 实现进度条显示

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...