RSS订阅 | 匿名投稿
您的位置:网站首页 > 字符串 > 正文

delphi字符串转换到指定格式的宽字符

作者:admin 来源:未知 日期:2010/5/3 21:40:54 人气: 标签:

本例效果图:



代码文件:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Memo1: TMemo;    Button1: TButton;    Edit1: TEdit;    procedure FormCreate(Sender: TObject);    procedure Button1Click(Sender: TObject);    procedure Memo1Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var  str: string;  pcw: PWideChar;  cw: WideChar;  i: Integer;begin  Memo1.Clear;  str := Edit1.Text;  pcw := PWideChar(str);  for i := 0 to StrLen(pcw) - 1 do  begin    cw := (pcw+i)^;    Memo1.Lines.Add(Format('$%.4x', [Ord(cw)]));    //Memo1.Lines.Add(Format('$%.4x', [Ord(str[i+1])])); {也可以用这句替换上面两行}  end;end;procedure TForm1.FormCreate(Sender: TObject);begin  Memo1.Clear;  Memo1.Align := alLeft;  Memo1.ScrollBars := ssVertical;end;procedure TForm1.Memo1Click(Sender: TObject);var  str: string;begin  str := Memo1.Lines[Memo1.CaretPos.Y];  Text := WideChar(StrToIntDef(str, 0));end;end.

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: