当前位置: 源码素材网 » Delphi教程 » 详情页

判断字符串是否为整数-判断是否含有中文 适用于Delphi

  •   时间:2019-07-22
  • 概述:判断整数

Delphi判断字符串是否是整数,判断是否含有中文字符,适用于Delphi7的源代码,比较简单的代码。以下是Delphi判断字符是否整数的代码:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Math;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
  s : string;
  i : integer;
begin
  s:=edit1.text;
  try
    i:=strtoint(s);
    if sign(i)=1 then  //添加单元Math或 if i>0 then ...
      label2.Caption := '是正整数'
    else
    begin
      if i=0 then
        label2.Caption := '是整数'
      else
        label2.Caption := '非正整数';
    end;
  except
    label2.Caption := '输入无效';
  end;
end;
end.

 Delphi判断字符串中是否包括有中文的代码:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, AxCtrls, OleCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
  str,s,sj: string;
  i: Integer;
begin
  str := Trim(Edit1.Text);
  i := 0;
  while i< length(str) do
  begin
    if Ord(str[i]) > $7F then
    begin
      s := copy(str,i,2);
      sj :=sj+ '"'+s+'"';
      i := i+2;
    end
    else  i:=i+1;
  end;
  Label2.Caption := '在字符串中含有汉字'+sj;
end;
end.

    相关声明:

      若“判断字符串是否为整数-判断是否含有中文 适用于Delphi”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。