Parse string with Parentheses to byte in CSharp
Description
The following code shows how to parse string with Parentheses to byte.
Example
using System;/* w w w. ja va2s . c om*/
using System.Globalization;
public class SByteConversion
{
NumberFormatInfo provider = NumberFormatInfo.CurrentInfo;
public static void Main()
{
string stringValue;
NumberStyles style;
stringValue = "(100)";
style = NumberStyles.AllowParentheses;
CallParseOperation(stringValue, style);
}
private static void CallParseOperation(string stringValue, NumberStyles style)
{
sbyte number;
try
{
number = sbyte.Parse(stringValue, style);
Console.WriteLine("SByte.Parse('{0}', {1})) = {2}",stringValue, style.ToString(), number);
}
catch (Exception e)
{
Console.WriteLine("'{0}' and {1} throw a {2}", stringValue, style.ToString(), e.GetType().Name);
}
}
}
The code above generates the following result.