Home  |  Delphi .net Home  |  System.Int64  |  Parse Method
Parse  
Method  
Converts a string representation of a Int64 into a Int64 value
Int64 Structure
System NameSpace
CF1.  Function Parse ( Value : String; ) : Int64;
CF2.  Function Parse ( Value:StringValue : String; Style : NumberStyles; ) : Int64;
CF3.  Function Parse ( Value:StringValue : String; FormatProvider : IFormatProvider; ) : Int64;
CF4.  Function Parse ( Value:StringValue : String; Style : NumberStyles; FormatProvider : IFormatProvider; ) : Int64; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Attempts to parse the Value string into a value between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807, returning a Int64 object with this value.
 
The Style parameter determines the allowed number content. It is an enumerated type that is treated as a set of flags (it has the [Flags] attribute). This means that multiple values may be set, using logical or. The possible values are :
 
AllowCurrencySymbol Allow for ?,$ ...
AllowExponentE+000 format
AllowThousandsFor example : 1,000,000
AllowDecimalPointFor example : 123.456
AllowParenthesesFor example (1234)
AllowTrailingSignFor example : 123-
AllowLeadingSignFor example : -123
AllowTrailingWhiteAllow trailing blanks
AllowLeadingWhiteAllow leading blanks
AllowHexSpecifierFor example : 0x2bcd

 
Note that not all of these allowances are meaningful for Int16 values.
 
The FormatProvider option allows for customised formatting and is beyond the scope of Delphi Basics.
Notes
Warning : An exception is thrown if the parse encounters unexpected characters.
References
NumberStyles
Microsoft MSDN Links
System
System.Int64
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

var
  intStr : String;
  result : Int64;

begin
  intStr := '12345678';
  result := System.Int64.Parse(intStr);
  Console.WriteLine('''' + intStr + ''' parses to {0}', result.ToString);

  Console.ReadLine;
end.
Show full unit code
  '12345678' parses to 12345678
Using NumberStyles
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

var
  style  : NumberStyles;
  intStr : String;
  result : Int64;

begin
  // Allow for hex values and leading/trailing blanks
  style := NumberStyles.AllowLeadingWhite  or
           NumberStyles.AllowTrailingWhite or
           NumberStyles.AllowHexSpecifier;

  intStr := ' 1234567890ABCDEF ';   // Hex 1234567890ABCDEF =
  result  := System.Int64.Parse(intStr, style);
  Console.WriteLine('''' + intStr + ''' parses to {0}', result.ToString);

  // Or more simply using one combined number style value
  style := NumberStyles.HexNumber;

  intStr := ' FFFFFFFFFFFFFF00 ';   // Hex FFFFFFFFFFFFFF00 = -256
  result  := System.Int64.Parse(intStr, style);
  Console.WriteLine('''' + intStr + ''' parses to {0}', result.ToString);

  Console.ReadLine;
end.
Show full unit code
  ' 1234567890ABCDEF ' parses to 1311768467294899695
  ' FFFFFFFFFFFFFF00 ' parses to -256
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author