本文整理自网络,侵删。
unit Unit2;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, SynEdit, SynMemo, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ExtCtrls;
type TForm2 = class(TForm) OpenDialog1: TOpenDialog; SynMemo1: TSynMemo; SynMemo2: TSynMemo; Panel1: TPanel; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form2: TForm2;
implementation
{$R *.dfm}
function IsHZ(ch: WideChar): boolean;var i: integer;begin i := ord(ch); if (i < 19968) or (i > 40869) then result := false else result := true;end;
procedure TForm2.Button1Click(Sender: TObject);var SS: TStringStream; S: string; sList: TStringList; i: integer; str: string; bz: Boolean;begin if OpenDialog1.Execute then begin SS := TStringStream.Create('', TEncoding.UTF8); sList := TStringList.Create; try SS.LoadFromFile(OpenDialog1.Filename); SynMemo1.Lines.LoadFromStream(SS); SynMemo1.Lines.Text := UTF8Decode(SynMemo1.Lines.Text);
S := SynMemo1.Lines.Text; bz := False; for i := 0 to S.Length - 1 do begin if (IsHZ(S[i]) or (S[i] in ['0'..'9']) or (S[i] in ['a'..'z']) or (S[i] in ['A'..'Z']) or (S[i] in ['.', '\', '-', '[', ']', ':'])) and (not (S[i] in [' '])) then begin str := str + S[i]; bz := true; end else bz := False;
if (str.Length > 0) and bz = false then begin if str.Trim <> '' then sList.add(str); str := ''; end; end; SynMemo2.Lines := sList; finally sList.free; SS.Free; end;
end;
end;
end.
相关阅读 >>
Delphi 文件/流的加密解密单元 unit_compress.pas
Delphi xe更改ttrayicon系统任务栏图标(无模糊)
Delphi分别连接ms sqlserver、oracle和access数据库的连接字符串
Delphi 10.3.x 截取字符串函数substring 和copy()常用字串符处理函数用法
更多相关阅读请进入《Delphi》频道 >>