C# UInt32 Parse(String, NumberStyles, IFormatProvider)

Description

UInt32 Parse(String, NumberStyles, IFormatProvider) converts the string representation of a number in a specified style and culture-specific format to its 32-bit unsigned integer equivalent.

Syntax

UInt32.Parse(String, NumberStyles, IFormatProvider) has the following syntax.


[CLSCompliantAttribute(false)]/*from  ww w  .  j av a2s.com*/
public static uint Parse(
  string s,
  NumberStyles style,
  IFormatProvider provider
)

Parameters

UInt32.Parse(String, NumberStyles, IFormatProvider) has the following parameters.

  • s - A string representing the number to convert. The string is interpreted by using the style specified by the style parameter.
  • style - A bitwise combination of enumeration values that indicates the style elements that can be present in s. A typical value to specify is Integer.
  • provider - An object that supplies culture-specific formatting information about s.

Returns

UInt32.Parse(String, NumberStyles, IFormatProvider) method returns A 32-bit unsigned integer equivalent to the number specified in s.

Example

The following example uses the Parse(String, NumberStyles, IFormatProvider) method to convert various string representations of numbers to 32-bit unsigned integer values.


using System;/*from   w  w  w .  j a v a2  s  . c  o  m*/
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] cultureNames= { "en-US", "fr-FR" };
      NumberStyles[] styles= { NumberStyles.Integer,
                               NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
      string[] values = { "123423", "+123423.0", "+123423,0", "-123423.00",
                                 "-123423,00", "123423.1", "123423,1" };

      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         Console.WriteLine(ci.DisplayName);
         foreach (NumberStyles style in styles)
         {
            Console.WriteLine(style.ToString());
            foreach (string value in values)
            {
               try {
                  Console.WriteLine("      Converted '{0}' to {1}.", value,
                                    UInt32.Parse(value, style, ci));
               }
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);
               }      
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt32 type.",
                                    value);
               }
            }
         }
      }                                    
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version