using System;
using System.Globalization;
public class StringParsing
{
public static void Main()
{
string numericString;
NumberStyles styles;
numericString = "22,593";
styles = NumberStyles.Integer | NumberStyles.AllowThousands;
CallTryParse(numericString, styles);
}
private static void CallTryParse(string stringToConvert, NumberStyles styles)
{
Console.WriteLine(stringToConvert);
short number;
bool result = Int16.TryParse(stringToConvert, styles,CultureInfo.InvariantCulture, out number);
if (result)
Console.WriteLine(stringToConvert, number);
else
Console.WriteLine("failed.");
}
}
|