Parse byte value with trailing sign or leading sign
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string value;
NumberStyles style;
byte number;
// Parse value with trailing sign.
style = NumberStyles.Integer | NumberStyles.AllowTrailingSign;
value = " 1+";
number = Byte.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
// Parse value with leading sign.
value = " +2 ";
number = Byte.Parse(value, style);
Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
}
Related examples in the same category