System.SysUtils.TryStrToInt

De RAD Studio API Documentation
Aller à : navigation, rechercher

Delphi

function TryStrToInt(const S: string; out Value: Integer): Boolean;

C++

extern DELPHI_PACKAGE bool __fastcall TryStrToInt(const System::UnicodeString S, /* out */ int &Value)/* overload */;

Propriétés

Type Visibilité  Source Unité  Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils


Description

Convertit en nombre une chaîne qui représente un entier (décimal ou hexadécimal), avec renvoi d'un code de succès booléen.

TryStrToInt convertit la chaîne S, qui représente un nombre entier, en notation décimale ou hexadécimale, assigné à Value. Si S ne représente pas un nombre valide, TryStrToInt renvoie False, sinon TryStrToInt renvoie True.

TryStrToInt prend en charge les chaînes des notations hexadécimales suivantes :

  • Delphi : $1234 et 0x1234.
  • C++ : 0x1234.

Pour accepter les valeurs décimales et pas les valeurs hexadécimales dans la chaîne de saisie, utilisez un code similaire à celui-ci :

Delphi:
function TryDecimalStrToInt( const S: string; out Value: Integer): Boolean;
begin
  result := (pos('$',S)=0) and ((pos('x',S)=0)) and TryStrToInt(S,Value);
end;
C++ :
bool __fastcall TForm1::TryDecimalStrToInt(const System::UnicodeString S, int &Value)
{
  bool result;
  result= (Pos('x',S)==0) && TryStrToInt(S,Value);
  return result;
}

Voir aussi