?? mainunit.pas
字號:
unit mainunit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
procedure CountChineseChars(SpecStr:String);
procedure UseByteType(SpecStr:String);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CountChineseChars(SpecStr:String);
var
WSStr:WideString;
TempStr:String;
I,E,C,O:integer;
begin
WSStr:=SpecStr;
E:=0;
C:=0;
O:=0;
for I:=1 to Length(WSStr) do
begin
if (ord(WSStr[I])>=33)and(ord(WSStr[I])<=127) then
begin
TempStr:=WSStr[I];
if (TempStr[1] in ['a'..'z','A'..'Z']) then
Inc(E)
else
Inc(O);
end
else
begin
if (ord(WSStr[I])>=127) then
begin
Inc(C);
end;
end;
end;
Application.MessageBox(Pchar('該字符串的組成結構為:漢字'+IntToStr(C)+'個,'+'英文字母'+IntToStr(E)+'個,'+'其他類型字符'+IntToStr(O)+'個'),'使用WideString數據類型分析字符串組成結構',mb_ok+mb_iconinformation);
end;
procedure TForm1.UseByteType(SpecStr:String);
var
I,E,C,O:integer;
begin
E:=0;
C:=0;
O:=0;
for I:=1 to Length(SpecStr) do
begin
if (ByteType(SpecStr,I)=mbSingleByte) then
begin
if (SpecStr[I] in ['a'..'z','A'..'Z']) then
Inc(E)
else
Inc(O);
end
else
Inc(C);
end;
Application.MessageBox(Pchar('該字符串的組成結構為:漢字'+IntToStr(C div 2)+'個,'+'英文字母'+IntToStr(E)+'個,'+'其他類型字符'+IntToStr(O)+'個'),'使用ByteType方法分析字符串組成結構',mb_ok+mb_iconinformation);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CountChineseChars(Edit1.Text);
Edit1.SetFocus;
Edit1.SelectAll;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UseByteType(Edit1.Text);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -