System.SysUtils.TryStrToInt64

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function TryStrToInt64(const S: string; out Value: Int64): Boolean;

C++

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

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Converts a string that represents an integer (decimal or hex notation) into a number.

TryStrToInt64 converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number, which is assigned to Value. Value is expressed as a 64 bit sized integer. If S does not represent a valid number, TryStrToInt64 returns False; otherwise TryStrToInt64 returns True.

TryStrToInt64 supports strings in the following hexadecimal notations:

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


To accept decimal but not hexadecimal values in the input string, you may use code like this:

Delphi:

function TryDecimalStrToInt64( const S: string; out Value: Int64): Boolean;
begin
  result := (pos('$',S)=0) and ((pos('x',S)=0)) and TryStrToInt64(S,Value);
end;

C++:

bool __fastcall TForm1::TryDecimalStrToInt64(const System::UnicodeString S, __int64 &Value)
{
  bool result;
  result= (Pos('x',S)==0) && TryStrToInt64(S,Value);
  return result;
}

See Also