private static double _convertArchitectualStringToValueInInches(string architecturalString)
{
// for details on where this solution came from, check here: http://stackoverflow.com/questions/22794466/parsing-all-possible-types-of-varying-architectural-Distance-input
// answer by Trygve Flathen: http://stackoverflow.com/users/2795177/trygve-flathen
//trim the input
architecturalString = architecturalString.Trim();
//define the regular expression (witchcraft)
String expression = "^\\s*(?<minus>-)?\\s*(((?<feet>\\d+)(?<inch>\\d{2})(?<sixt>\\d{2}))|((?<feet>[\\d.]+)')?[\\s-]*((?<inch>\\d+)?[\\s-]*((?<numer>\\d+)/(?<denom>\\d+))?\")?)\\s*$";
//find out what strings match
Match match = new Regex(expression).Match(architecturalString);
//test for failure cases
if (!match.Success || architecturalString == "" || architecturalString == "\"")
{
throw new FormatException("Input was not a valid architectural string");
}
//parse the results
Int32 sign = match.Groups["minus"].Success ? -1 : 1;
Double feet = match.Groups["feet"].Success ? Convert.ToDouble(match.Groups["feet"].Value) : 0;
Int32 inch = match.Groups["inch"].Success ? Convert.ToInt32(match.Groups["inch"].Value) : 0;
Int32 sixt = match.Groups["sixt"].Success ? Convert.ToInt32(match.Groups["sixt"].Value) : 0;
Int32 numer = match.Groups["numer"].Success ? Convert.ToInt32(match.Groups["numer"].Value) : 0;
Int32 denom = match.Groups["denom"].Success ? Convert.ToInt32(match.Groups["denom"].Value) : 1;
//combine the results
double result = sign * (feet * 12 + inch + sixt / 16.0 + numer / Convert.ToDouble(denom));
return result;
}