首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

文件内容读取解决方案

2012-02-25 
文件内容读取下面是我现在的代码,现在能实现了从TXT文件从读取信息,我是根据Edit1.Text中字符串中的时间来

文件内容读取
下面是我现在的代码,现在能实现了从TXT文件从读取信息,我是根据Edit1.Text中字符串中的时间来读取的,如果Edit1.Text中字符串中的时间是2007-05-08   ,我TXT文件中最后的时间是2007-05-08   那么我在MEMO中显示的也就是2007-05-08   这天纪录的内容。如果我Edit1.Text中字符串中的时间是2007-05-01,那么   MEMO中显示的也就是2007-05-01   到2007-05-08     这几天的内容。   请问怎么样写才能只显示Edit1.Text中字符串中的时间对应的内容,其他时间纪录的内容不显示

var
    s1,s2,S,ALLText:string;
    F:textfile;
    nPosBegin,nPosEnd:integer;
begin

    Edit1.Text:=ShellTreeView1.Path;
    s1:=ExtractFileName(Edit1.Text);
    nPosBegin:=Pos( ', ',s1);
    nPosEnd:=LastDelimiter( ', ',s1);
    s2:=Copy(s1,nPosBegin+1,nPosEnd-nPosBegin-1);
//     showmessage(s2);

      Assignfile(F, 'E:\operview参数备份\Readme.txt ');
      reset(F);
      while   not   EOF   (F)   do   begin
      readln(F,S);
      if   CompareStr(S,s2)=0           then
          while   not   EOF   (F)   do   begin
              readln(F,S);
              ALLText:=ALLText   +   S+#13#10;
              end;
              Memo1.Clear;
              memo1.Text:=ALLText;          
      end;
      closefile(F);
end;

[解决办法]
pos判断一下字符串
[解决办法]
你应该用TStringList
AStringList.LoadFromFile(...);
for I:=0 to AStringList.Count-1 do begin
if Pos(AStringList[I], YourStr)=1 then
...
end;

热点排行