TstringList在Delphi中 [英] TstringList In Delphi

查看:48
本文介绍了TstringList在Delphi中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加数据(字符串类型或整数和...)到'TStringList'从'TextFile'然后计算相同的数据(这= 5,或= 3,123) = 12例如)最后显示进入'ListBox'或'TextBox'之类的东西,请帮助我认识Delphi的人。

How Can I Add Data(String type or integer and ...) To 'TStringList' From a 'TextFile'and then Count the same Data(this=5, or=3 ,123=12 for example) at last show into the 'ListBox' or 'TextBox' something like that,Please help me anyone who knows Delphi well.

推荐答案

添加数据,你会做类似的事情:

To add data, you'll do something like:
SLst := TStringList.Create;
//To add string to a TStringList:
SLst.Add('This is a string');
//or
SLst.Add(VariableName);

//To add integer
SLst.Add(IntToStr(55));
//or
SLst.Add(IntToStr(VariableName));



你将定义SLst:


you'll define SLst by:

var
  SLst: TStringList;





如果你想从文本文件中加载它:



And if you want to load it from a textfile:

SLst.LoadFromFile('C:\myfile.txt');



你用什么来计算相同的数据是什么意思?你的意思是计算文件中有多少行?如果是,那么:


And what do you mean by count the same data? You mean to count how much lines there are in the File? If yes, then:

Count := SLst.Count;





但是如果你想在备忘录中显示数据,那么请执行以下操作而不是以上所有代码:



But if you want to show the data in a Memo, then do the following instead of all the above code:

Memo1.Lines.LoadFromFile('C:\myfile.txt');
Count := Memo1.Lines.Count;





我希望我的答案有所帮助。



I hope my answer helped.


这篇关于TstringList在Delphi中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆