——此文章摘自《Delphi开发经验技巧宝典》定价
¥
特价
¥
购买>>http://track
linktech
cn/?m_id=dangdang&a_id=A
&l=
&l_type
=
width=
height=
border=
nosave>
字符中是否有双字节
中文所用的字符全是双字节字符英文所用的字节全是单字节字符也就是mbSingleByte本实例是用ByteType()函数返回字符串指定位置上的字符如果不是mbSingleByte则表示为双字节字符运行结果如图所示
http://developcsaicn/delphi/images/jpg>
图 判断字符中是否有双字节
主要代码如下
procedure TFormButtonClick(Sender: TObject);
var
ss: String;
i : Integer;
begin
s := EditText;
i := ;
while i<Length(s) do
begin
if (ByteType(Si) <> mbSingleByte) then
begin
s := s+ Copy(si)+ ;
i := i+;
end
else
i:= i+;
end;
LabelCaption := Trim(s);
end;
判数输入的字符串是否为整数
本实例是用库函数sign()来判断数字是否为整数当传入的值小于则返回;若传入的值大于则返回否则返回在用sign()函数时要在单元中加入Math单元运行结果如图所示
http://developcsaicn/delphi/images/jpg>
图 判数输入的字符串是否为整数
主要代码如下
procedure TFormButtonClick(Sender: TObject);
var
s : String;
i : Integer;
begin
s:=EditText;
try
i:=StrtoInt(s);
if sign(i)= then //添加单元Math或 if i> then
LabelCaption := 是正整数
else
begin
if i= then
LabelCaption := 是整数
else
LabelCaption := 非正整数;
end;
except
LabelCaption := 输入无效;
end;
end;
right>[http://developcsaicn/delphi/htm>] [http://developcsaicn/delphi/htm>] [http://developcsaicn/delphi/htm>] [http://developcsaicn/delphi/htm>] []