Description |
The StrToInt64Def function converts an Integer string, IntegerString such as '123' into an Int64 value, with a Default if the conversion fails.
It supports +ve and -ve numbers, and hexadecimal numbers, as prefixed by $ or 0x.
|
|
Notes |
No conversion errors are generated - bad conversions simply result in the Default being returned.
|
|
Related commands |
Int64 |
|
A 64 bit sized integer - the largest in Delphi |
IntToStr |
|
Convert an integer into a string |
StrToInt |
|
Convert an integer string into an Integer value |
StrToInt64 |
|
Convert an integer string into an Int64 value |
StrToIntDef |
|
Convert a string into an Integer value with default |
|
|
|
Example code : Converting decimal and hexadecimal numbers |
var
A, B, C, D, E, F : Int64;
begin
A := 32; B := StrToInt64Def('100', 0); // '100' string converted to 100 integer C := StrToInt64Def(' -12', 0); // Leading blanks are ignored D := StrToInt64Def('$1E', 0); // Hexadecimal values start with a '$' E := StrToInt64Def('-0x1E', 0); // ... or with a '0x' F := A + B + C + D + E; // Lets add up all these integers
WriteLn('A : '+IntToStr(A));
WriteLn('B : '+IntToStr(B));
WriteLn('C : '+IntToStr(C));
WriteLn('D : '+IntToStr(D));
WriteLn('E : '+IntToStr(E));
WriteLn('F : '+IntToStr(F));
end;
|
Show full unit code |
A : 32
B : 100
C : -12
D : 30
E : -30
F : 120
|
|
Example code : Catching string to integer conversion errors |
var
A : Int64;
begin // No need to catch conversion errors A := StrToInt64Def('100 ', 55); // Trailing blanks are not supported
WriteLn('Value = '+IntToStr(A));
A := StrToInt64Def('$FG' , 66); // 'G' is an invalid hexadecimal digit
WriteLn('Value = '+IntToStr(A));
end;
|
Show full unit code |
Value = 55
Value = 66
|
|