Inno Setup:从测试文件中删除空行

用户名

我们正在使用下面的代码从文本文件中删除空行,但是它不起作用。

function UpdatePatchLogFileEntries : Boolean;
var
a_strTextfile : TArrayOfString;
iLineCounter : Integer;
    ConfFile : String;

begin

ConfFile := ExpandConstant('{sd}\patch.log');
    LoadStringsFromFile(ConfFile, a_strTextfile);

    for iLineCounter := 0 to GetArrayLength(a_strTextfile)-1 do
    begin
         if (Pos('', a_strTextfile[iLineCounter]) > 0) then 
            Delete(a_strTextfile[iLineCounter],1,1);
    end;
     SaveStringsToFile(ConfFile, a_strTextfile, False);              
end;

请帮我。提前致谢。

TLama

因为数组的重新索引效率低下,并且拥有两个用于复制文件非空行的数组会不必要地变得复杂,所以建议您使用TStringListclass。它囊括了您需要的所有内容。在代码中,我将这样编写函数:

[Code]
procedure DeleteEmptyLines(const FileName: string);
var
  I: Integer;
  Lines: TStringList;
begin
  // create an instance of a string list
  Lines := TStringList.Create;
  try
    // load a file specified by the input parameter
    Lines.LoadFromFile(FileName);
    // iterate line by line from bottom to top (because of reindexing)
    for I := Lines.Count - 1 downto 0 do
    begin
      // check if the currently iterated line is empty (after trimming
      // the text) and if so, delete it
      if Trim(Lines[I]) = '' then
        Lines.Delete(I);
    end;
    // save the cleaned-up string list back to the file
    Lines.SaveToFile(FileName);
  finally
    // free the string list object instance
    Lines.Free;
  end;
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Unicode Inno Setup中的LoadStringFromFile和StringChangeEx(Ansi文件)

来自分类Dev

如何使用通配符测试Inno Setup中是否存在文件

来自分类Dev

Inno Setup:列出目录中的所有文件名

来自分类Dev

防止Inno Setup在卸载时删除某些文件

来自分类Dev

Inno Setup语法-OR,AND

来自分类Dev

Inno Setup查找子文件夹

来自分类Dev

如何在Inno Setup中删除非空文件夹

来自分类Dev

Inno Setup:使用任务功能删除文件夹

来自分类Dev

inno setup中的“ Not in a loop”错误

来自分类Dev

在Inno Setup中取消安装

来自分类Dev

Inno Setup中的TTreeView

来自分类Dev

Inno Setup中的条件DisableProgramGroupPage

来自分类Dev

在Inno Setup中创建ZIP文件

来自分类Dev

在Inno Setup中复制隐藏文件

来自分类Dev

从Inno Setup AppId中删除“ _is1”后缀

来自分类Dev

Inno Setup:在卸载过程中从安装程序读取文件

来自分类Dev

在Inno Setup中写入二进制文件

来自分类Dev

在Inno Setup中删除XML元素的内容

来自分类Dev

Inno Setup:在卸载过程中重新启动后删除文件夹

来自分类Dev

在Inno Setup中卸载期间,从所有用户配置文件中删除日志文件

来自分类Dev

如何在Inno Setup中删除由以前版本的应用程序添加的文件

来自分类Dev

如何在Inno Setup中捕获bat文件的错误消息以删除文件?

来自分类Dev

在Inno Setup中记录TWindowsVersion

来自分类Dev

Unicode Inno Setup中的LoadStringFromFile和StringChangeEx(Ansi文件)

来自分类Dev

Inno Setup是否应在Update上删除旧文件?

来自分类Dev

在Inno Setup中写入二进制文件

来自分类Dev

Inno Setup 中的动态密码

来自分类Dev

如何在 Inno Setup iss 文件中调用 GetNativeSystemInfo?

来自分类Dev

Inno setup 只删除文件夹

Related 相关文章

热门标签

归档