Home  |  Delphi .net Home  |  System.UInt32  |  Parse Method
  
Parse  
Method  
Converts a string representation of a UInt32 into a UInt32 value
UInt32 Structure
System NameSpace
CF1.  Function Parse ( Value : String ) : UInt32; Static;
CF2.  Function Parse ( Value : String; Style : NumberStyles ) : UInt32; Static;
CF3.  Function Parse ( Value : String; FormatProvider : IFormatProvider ) : UInt32; Static;
CF4.  Function Parse ( Value : String; Style : NumberStyles; FormatProvider : IFormatProvider ) : UInt32; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Attempts to parse the Value string into a value between 0 and 4,294,967,295, returning a UInt32 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.UInt32
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

var
  intStr : String;
  result : UInt32;

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

  Console.ReadLine;
end.
   '1234' parses to 1234
Using NumberStyles
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Globalization;

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

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

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

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

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

  Console.ReadLine;
end.
   ' 12ABCDEF ' parses to 313249263
   ' FFFFFF00 ' parses to 4294967040
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author