System.SysUtils.TryStrToInt

提供: RAD Studio API Documentation
移動先: 案内検索

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 */;

プロパティ

種類 可視性 ソース ユニット
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils


説明

整数(10 進数または 16 進数)を表す文字列を、Boolean 成功コードの数値に変換します。

TryStrToInt は、10 進か 16 進の整数型数値を表す文字列 S を数値に変換し、Value に代入します。 S が有効な数値を表していない場合、TryStrToInt は False を返します。そうでない場合、TryStrToInt は True を返します。

TryStrToInt は、次の 16 進数表記の文字列をサポートしています:

  • Delphi: $1234 および 0x1234.
  • C++: 0x1234

入力文字列として 16 進値ではなく 10 進値のみ指定可能とするには、以下のようなコードを使用してもかまいません。

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;
}

関連項目