delphi - Delphi-如何在保存之前删除非 ANSI(不可打印)字符?
问题描述
有人可以指导我以某种方式扩展此过程,以便在将流保存到文件之前删除所有不可打印字符或替换为 SPACE 吗?字符串从二进制中读取,最大大小为 1 MB。我的程序:
var
i : Word;
FileName : TFileName;
SizeofFiles,posi : Integer;
fs, sStream: TFileStream;
SplitFileName: String;
begin
ProgressBar1.Position := 0;
FileName:= lblFilePath.Caption;
SizeofFiles := StrToInt(edt2.Text) ;
posi := StrToInt(edt1.text) ;
fs := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
fs.Position := Posi ;
begin
SplitFileName := ChangeFileExt(FileName, '.'+ FormatFloat('000', i));
sStream := TFileStream.Create(SplitFileName, fmCreate or fmShareExclusive);
try
if fs.Size - fs.Position < SizeofFiles then
SizeofFiles := fs.Size - fs.Position;
sStream.CopyFrom(fs, SizeofFiles);
ProgressBar1.Position := Round((fs.Position / fs.Size) * 100);
finally
sStream.Free;
end;
end;
finally
fs.Free;
end;
end;
解决方案
你将无法再使用TStream.CopyFrom()
。您必须Read(Buffer)()
从源TStream
到本地字节数组,从该数组中删除您不想要的任何内容,然后Write(Buffer)()
将剩余字节到目标TStream
。
推荐阅读
- vb.net - ExecuteReader 需要一个打开的连接。连接的当前状态为关闭
- phpunit - 如何在 PhpStorm 中设置测试配置以使用不同的解释器
- javascript - 对象到数组返回未定义
- php - PDO::prepare 没有正确转义来自 iPhone 的输入
- python - Ubuntu 18.04 中的 Spyder 2
- autohotkey - 是否有可能让 ahk 脚本间隔少于一毫秒?
- css - 如何构建一个 CSS flex-grid,在子元素之间有空格,但没有空的地方?
- javascript - 对匹配特定地址的对象值求和
- python - 张量流:tf.constant()错误的输出
- vba - Excel VBA - 转换为单词的边框问题