NumberStyles.Integer | NumberStyles.AllowExponent
using System;
using System.Globalization;
public class StringParsing
{
public static void Main()
{
string numericString;
NumberStyles styles;
numericString = "12E-01";
styles = NumberStyles.Integer | NumberStyles.AllowExponent;
CallTryParse(numericString, styles);
numericString = "12E03";
styles = NumberStyles.Integer | NumberStyles.AllowExponent;
CallTryParse(numericString, styles);
}
private static void CallTryParse(string stringToConvert, NumberStyles styles)
{
int number;
CultureInfo provider = CultureInfo.InvariantCulture;
bool result = Int32.TryParse(stringToConvert, styles, provider, out number);
if (result)
Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
else
Console.WriteLine("Attempted conversion of '{0}' failed.",
Convert.ToString(stringToConvert));
}
}
Related examples in the same category