Fórum Testar se em uma string contem um numero #290572
03/08/2005
0
ex.:
resultado:= testanumero(´10´); function testanumero(texto:string):boolean; begin //aqui está a duvida if texto = numero then result:= True; end;
Atualmente estou utilizando a função [b:7a578fbcf8]strtoint[/b:7a578fbcf8] e trato com [b:7a578fbcf8]execpt[/b:7a578fbcf8]
Sistemald
Curtir tópico
+ 0Posts
03/08/2005
Rjun
resultado := testanumero(´10´); function testanumero(texto: string): boolean; var i: integer; begin result := false; for i := 1 to length(texto) do if texto[i] in [´0´..´9´] then begin result:= True; exit; end; end;
Gostei + 0
03/08/2005
Fx|hand
[b:751de81eea]TryStrToInt()[/b:751de81eea] .... e ficou assim...
{MINHA FUNÇÃO}
Function IsNum(S:String): Boolean;
var
OutVar: Integer;
begin
Result := TryStrToInt(s,OutVar);
end;
{FIM DELA}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage (BooltoStr(IsNum(Edit1.Text)));
end;
{Ela manda um resultado em Boolean... vc poderia trocar e fazer ela retornar o valor ´0´ (em integer) se for o seu caso... ou se a String for um numero, ele Retorna o numero q foi lançado pra função.... a função ficaria assim}
{MINHA FUNÇÃO}
Function IsNum2(S:String): Integer;
var
OutVar: Integer;
begin
Val(S, OutVar, OutVar);
Result := OutVar;
end;
{FIM DELA}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage (IntToStr(IsNum(Edit1.Text)));
end;
Gostei + 0
03/08/2005
Sistemald
TryStrtoInt
Valeu galera
Gostei + 0
03/08/2005
Kotho
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)