// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text.RegularExpressions; namespace E { public class Program { private static readonly Regex re = new Regex(@"(\d+) (\d+)/(\d+)", RegexOptions.Compiled); public static double FractionParse(string s) { Match m = re.Match(s); if(m.Success) { return int.Parse(m.Groups[1].Value) + int.Parse(m.Groups[2].Value) / (double)int.Parse(m.Groups[3].Value); } else { throw new ArgumentException(s + " is not a valid fraction"); } } public static void Main(string[] args) { string s = "5 1/8"; Console.WriteLine(FractionParse(s)); } } }