Parse string to byte with number style setting : byte « Data Types « C# / C Sharp






Parse string to byte with number style setting

    

using System;
using System.Globalization;

public class MainClass
{
   public static void Main()
   {
      string byteString; 
      NumberStyles styles;

      byteString = "1024";
      styles = NumberStyles.Integer;
      CallTryParse(byteString, styles);
   }

   private static void CallTryParse(string stringToConvert, NumberStyles styles)
   {  
      Byte byteValue;
      bool result = Byte.TryParse(stringToConvert, styles, 
                                  null as IFormatProvider, out byteValue);
      if (result){
         Console.WriteLine("Converted '{0}' to {1}",stringToConvert, byteValue);
      }else{
         Console.WriteLine("Attempted conversion of '{0}' failed.", stringToConvert.ToString());
      }
   }
}

   
    
    
    
  








Related examples in the same category

1.An int, a short, and a float are included in a mathematical expression giving a float result.
2.Use byteUse byte
3.Format byte with X4
4.Read short from byte array
5.Write short value to byte array
6.Read Int 24 from byte array
7.Read int 32 from byte array
8.Write int 32 to byte array
9.Byte array Index Of
10.Convert int to byte
11.Convert double to byte
12.Using Convert.ToByte to convert value to byte
13.Parse string to byte and catch the OverflowException and FormatException
14.Parse hexadecimal number to byte decimal
15.byte default format and leading zeros format
16.Format byte value to its hexadecimal form
17.Convert byte value to its base 2(Binary), base 8(Octal) and base 16(Hex) forms
18.Byte value binary and operation
19.byte hexadecimal literal
20.Byte.MaxValue, Byte.MinValue
21.Parse string with a culture-specific format to byte with IFormatProvider
22.Parse byte value with trailing sign or leading sign
23.Converts Byte to string with the culture-specific formatting information.
24.byte value standard string format
25.Format a byte value to string with culture-specific formatting information.
26.Tries to parse string to Byte
27.Convert Bytes To String
28.Count Non Zero Bytes
29.Get Unsigned Byte Value
30.Convert Byte to Short
31.Convert Byte to Integer
32.Get Compressed Int Size
33.Compress Int