delphi的窗体文件(dfm)文件中的汉字提取出来?


本文整理自网络,侵删。

 
用记事本打开dfm文件,如果包括中文的话,都是用 #+一串数字表示的如何把这个转换出来?
解决方案 ?
  

 "#+一串数字表示的 " 这就是汉字的Unicode编码
很容易转换的

unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
uses myfunc;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  cText:TextFile;
  s,t:string;
  w:widestring;   //#后面代表的汉字
  i,n,lens,j:Integer;
begin
  AssignFile(cText,'cnCurrencyU.dfm');
  try
    Reset(cText);
    while not eof(cText) do
      begin
        Readln(cText,s);
        if pos('#',s)>0 then
          begin
            lens:=Length(s);
            s:=copy(s,pos('#',s),lens-pos('#',s)+1);
            n:=SubStrNum('#',s); //myfunc
            Memo1.Lines.Add(s);
            w:='';
            for i := 1 to n do
              begin
                j:=pos('#',s);
                t:=Copy(s,j+1,5);
                Delete(s,1,j);
                w:=w+widechar(strtoint(t));
              end;
              Memo1.Lines.Add(w);
        end;
      end;
  finally
    CloseFile(cText);
  end;end;end.
  
  

//1.生成一个Unicode与汉字的对应表
//2.将文本文件中的Unicode转为中文
下面是Unicode与汉字的对应表var
  w: WideString;
  i: Integer;
  s: string;
  List: TStringList;
begin
  List := TStringList.Create;  for i := $4e00 to $9fa5 do
  begin
    s := #36 + IntToHex(i,4); {#36 是 $ 字符}
    w := WideChar(i);
    List.Add(s + '=' + w);
  end;  List.SaveToFile('c:\temp\Unicode-Hz.txt');
  List.Free;
end;

相关阅读 >>

Delphi 有关debughook

Delphi 释放bitmap

Delphi 使控件支持鼠标滚轴消息

Delphi 判断尾串是否匹配,不分大小写

Delphi 多次改变 richedit.text部份文本的颜色后,出现所有字体都变色的的解决办法

Delphi 2010/xe下隐藏程序在系统任务栏的图标

Delphi中inputbox 和inputquery 函数的使用

Delphi webbrowser多次执行documentcomplete

Delphi 利用createservice写与桌面交互的win32服务

Delphi 7 中dbgrid的排序

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...