delphi 快速读取文件 然后用TPerlRegEx类提取需要内容
来源:互联网 发布:如何查看淘宝买家信用 编辑:程序博客网 时间:2024/05/22 01:32
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,PerlRegEx;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function MMFileToString(const AFilename: string): string;var hFile: THandle; hFileMap: THandle; hiSize: DWORD; loSize: DWORD; text: string; view: pointer;begin Result := ''; if AFilename = '' then Exit; if not FileExists(AFilename) then Exit; {Open the file} hFile := CreateFile(PChar(AFilename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if hFile <> INVALID_HANDLE_VALUE then begin loSize := GetFileSize(hFile, @hiSize); {File was opened successfully, now map it:} hFileMap := CreateFileMapping(hFile, nil, PAGE_READONLY, hiSize, loSize, 'TextForString'); if (hFileMap <> 0) then begin if (GetLastError() = ERROR_ALREADY_EXISTS) then begin MessageDlg('Mapping already exists - not created.', mtWarning, [mbOk], 0); CloseHandle(hFileMap) end else begin try {File mapped successfully, now map a view of the file into the address space:} view := MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0); if (view <> nil) then begin {View mapped successfully} CloseHandle(hFile); {Close file handle - as long is view is open it will persist} SetLength(Result, loSize); Move(view^, Result[1], loSize); end else MessageDlg('Unable to map view of file. ' + SysErrorMessage(GetLastError), mtWarning, [mbOk], 0); finally UnmapViewOfFile(view); {Close view} CloseHandle(hFileMap); {Close mapping} end end end else begin MessageDlg('Unable to create file mapping. ' + SysErrorMessage(GetLastError), mtWarning, [mbOk], 0); end; end else begin MessageDlg('Unable to open file. ' + SysErrorMessage(GetLastError), mtWarning, [mbOk], 0); end;end;procedure TForm1.Button1Click(Sender: TObject);varstr:string;reg: TPerlRegEx;List: TStrings;begin reg:=TPerlRegEx.Create; reg.Subject := MMFileToString(Edit2.Text); reg.RegEx := Edit1.Text; while reg.MatchAgain do begin str:=str+reg.MatchedText+#13#10; end; Memo1.Text:=str; FreeAndNil(reg);end;end.
- delphi 快速读取文件 然后用TPerlRegEx类提取需要内容
- 向文件中追加内容,然后读取出来
- DELPHI 正则表达式 TPerlRegEx
- DELPHI 正则表达式 TPerlRegEx
- VB 快速读取文件内容的方法
- powershell 快速读取二进制大文件内容
- Delphi 正则表达式TPerlRegEx 类的属性与方法
- python 实现文件打开读取内容然后写入更新内容(文件只打开一次)
- Delphi读取文本内容
- delphi的正则TPerlRegEx使用方法
- Delphi 正则表达式 与 TPerlRegEx
- golang语言实现读取csv文件内容,把相同的内容提取到另外一个文件
- netCDF文件内容提取
- 读取文件 然后逆序输出
- org.apache.commons.io.IOUtils工具类快速读取文件内容
- Python 快速读取文件内容到列表中
- python跳过第一行快速读取文件内容
- Python3跳过第一行快速读取文件内容
- 如何实现多个数据库连接(SQL,ACCESS,ORACLE)等
- 甲骨文总裁拉里·埃里森在耶鲁大学的演讲(史上最强的演讲)
- Java的时间处理
- ubuntu nginx php 配置
- linux 奇淫巧计 Manual FIle Locking
- delphi 快速读取文件 然后用TPerlRegEx类提取需要内容
- linux sar
- ubuntu 复制文件到xp (How i can copy file from server(OS:ubuntu 10.04) to my PC
- 在 Vim 中设置 Tab
- Linux安装程序Anaconda分析(续)
- 怎么样获得直觉能力————摘录
- struts2两种Action驱动模式之Model-Driven(模型驱动)
- [水滴]C中变量的定义和声明的区别
- 比尔·盖茨谈论“以疫苗减少人口”