我在 Delphi 7 中使用 EncodeString 对从源文本文件加载的字符串进行编码。在源文本文件中,每一行都是一条记录。现在,我想使用函数 EncodeString ,它是 Base64 函数来编码每一行字符串并写入一个新的目标文本文件。我的目的是源文本文件中的一行字符串应该编码为目标文本文件中的一行加密字符串。但每行编码为 3 行加密字符串。3行有几个换行符。如何删除换行符?
代码:
procedure TForm1.Button1Click(Sender: TObject);
var
i,sum:integer;
begin
memoSource.Lines.LoadFromFile('source.txt');
sum:=memoSource.Lines.Count;
assignFile(targetFile,'target.txt');
rewrite(targetFile);
memoTarget.Clear;
for i:=0 to sum-1 do
begin
memoTarget.Lines.Append(EncodeString(memoSource.Lines.Strings[i]));
Writeln(targetFile,EncodeString(memoSource.Lines.Strings[i]));
//Write(targetFile,EncodeString(memoSource.Lines.Strings[i])); //use write but line-feed still in the strings
end;
end;
这是源文本内容:
line 1: this is a soure text to test , every line is one record. this is a soure text to test , every line is one record. this is a soure text to test , every line is one record.
line 2: this is a soure text to test , every line is one record. this is a soure text to test , every line is one record. this is a soure text to test , every line is one record.
line 3: this is a soure text to test , every line is one record. this is a soure text to test , every line is one record. this is a soure text to test , every line is one record. code here
这是 EncodeString 文本内容:
bGluZSAxOiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLg==
bGluZSAyOiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLg==
bGluZSAzOiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZSBpcyBvbmUg
cmVjb3JkLiB0aGlzIGlzIGEgc291cmUgdGV4dCB0byB0ZXN0ICwgZXZlcnkgbGluZS
我需要在每个目标文本文件行尾换行,以便区分每一行。
多谢!