Delphi 2009新增单元 Character[2]

IsLetter、IsUpper、IsLower、IsDigit、IsNumber

IsLetter: {是否是个字母; 范围 A..Z 与 a..z}
IsUpper: {是否是个大写字母; 范围 A..Z}
IsLower: {是否是个小写字母; 范围 a..z}
IsDigit: {是否是个十进制数字; 范围 0..9}
IsNumber: {是否是个数字符号; 范围包括 0..9, 还有 ASCII 码中的 178、179、185、188、189、190 等}

测试代码:

unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
type
 TForm1 = class(TForm)
  Button1: TButton;
  Button2: TButton;
  Button3: TButton;
  Button4: TButton;
  Button5: TButton;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure Button3Click(Sender: TObject);
  procedure Button4Click(Sender: TObject);
  procedure Button5Click(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
uses Character;
{IsLetter: 是否是个字母}
procedure TForm1.Button1Click(Sender: TObject);
var
 b1,b2,b3: Boolean;
begin
 b1 := IsLetter('A'); {是}
 b2 := IsLetter('a'); {是}
 b3 := IsLetter('9'); {否}
 ShowMessageFmt('%s,%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True),BoolToStr(b3,True)]);
 {True,True,False}
 b1 := IsLetter('D2009', 1);
 b2 := IsLetter('D2009', 2);
 ShowMessageFmt('%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True)]);
 {True,False}
end;
{IsUpper: 是否是个大写字母}
procedure TForm1.Button2Click(Sender: TObject);
var
 b1,b2,b3: Boolean;
begin
 b1 := IsUpper('A'); {是}
 b2 := IsUpper('a'); {否}
 b3 := IsUpper('9'); {否}
 ShowMessageFmt('%s,%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True),BoolToStr(b3,True)]);
 {True,False,False}
 b1 := IsUpper('Delphi', 1);
 b2 := IsUpper('Delphi', 2);
 ShowMessageFmt('%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True)]);
 {True,False}
end;
{IsLower: 是否是个小写字母}
procedure TForm1.Button3Click(Sender: TObject);
var
 b1,b2,b3: Boolean;
begin
 b1 := IsLower('A'); {否}
 b2 := IsLower('a'); {是}
 b3 := IsLower('9'); {否}
 ShowMessageFmt('%s,%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True),BoolToStr(b3,True)]);
 {False,True,False}
 b1 := IsLower('Delphi', 1);
 b2 := IsLower('Delphi', 2);
 ShowMessageFmt('%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True)]);
 {False,True}
end;
{IsDigit: 是否是个十进制数字}
procedure TForm1.Button4Click(Sender: TObject);
var
 b1,b2,b3: Boolean;
begin
 b1 := IsDigit('A'); {否}
 b2 := IsDigit('½'); {否}
 b3 := IsDigit('9'); {是}
 ShowMessageFmt('%s,%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True),BoolToStr(b3,True)]);
 {False,False,True}
 b1 := IsDigit('D2009', 1);
 b2 := IsDigit('D2009', 2);
 ShowMessageFmt('%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True)]);
 {False,True}
end;
{IsNumber: 是否是个数字符号}
procedure TForm1.Button5Click(Sender: TObject);
var
 b1,b2,b3: Boolean;
begin
 b1 := IsNumber('A'); {是}
 b2 := IsNumber('½'); {是}
 b3 := IsNumber('9'); {否}
 ShowMessageFmt('%s,%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True),BoolToStr(b3,True)]);
 {False,True,True}
 b1 := IsNumber('123¹²³¼½¾', 1);
 b2 := IsNumber('123¹²³¼½¾', 4); {这里的 9 个字符全都复合}
 ShowMessageFmt('%s,%s', [BoolToStr(b1,True),BoolToStr(b2,True)]);
 {True,True}
end;
end.

时间: 2024-12-21 21:07:14

Delphi 2009新增单元 Character[2]的相关文章

Delphi 2009新增单元 Character[1]

ToUpper.ToLower - 字符与字符串的大小写转换 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TBu

Delphi 2009的反射单元(ObjAuto)

ObjAuto 单元应该算是对 TypInfo 单元的功能扩展吧? 它提供了 5 个方法: GetMethods.GetMethodInfo.CreateMethodPointer.ReleaseMethodPointer.ObjectInvoke 通过 GetMethods.GetMethodInfo 可以获取类公用成员的详细信息. 通过 TypInfo 只能获取 published 区中成员的信息(例子); 通过 ObjAuto 也能获取 public 区的成员信息. 本例效果图: 本例有两

Delphi 2009泛型容器单元(Generics.Collections)[4]: TDictionary<T>

TDictionary 类似哈希表. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Edit1: TEdit; Edit2: TEdit; Button1: TButton; Button2: TB

Delphi 2009泛型容器单元(Generics.Collections)[3]: TStack<T>

TQueue 和 TStack, 一个是队列列表, 一个是堆栈列表; 一个是先进先出, 一个是先进后出. TStack 主要有三个方法.一个属性: Push(压栈).Pop(出栈).Peek(查看下一个要出栈的元素); Count(元素总数). 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdC

Delphi 2009泛型容器单元(Generics.Collections)[2]: TQueue<T>

TQueue 和 TStack, 一个是队列列表, 一个是堆栈列表; 一个是先进先出, 一个是先进后出. TQueue 主要有三个方法.一个属性: Enqueue(入列).Dequeue(出列).Peek(查看下一个要出列的元素); Count(元素总数). 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialog

Delphi 2009泛型容器单元(Generics.Collections)[1]: TList

Delphi 2009 新增了泛型容器单元: Generics.Collections, 同时还有一个 Generics.Defaults 单元做支持. Generics.Collections 包含了以下实用类: TList<T> TQueue<T> TStack<T> TDictionary<TKey,TValue> TObjectList<T> TObjectQueue<T> TObjectStack<T> TObj

Delphi 2009之TStringBuilder类[5]: Chars[]属性与CopyTo方法

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Se

Delphi 2009之TStringBuilder类[4]: Insert与Remove

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R

Delphi 2009之TStringBuilder类[3]: Replace

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: