public Tuple <string, string> Convert(string search) { string title = search; string output = null; try { var unitString = search; string targetUnitString = null; string targetExtraUnitString = null; var arrowFields = search.Separate("->"); if (arrowFields != null) { unitString = arrowFields.Item1; targetUnitString = arrowFields.Item2; } if (targetUnitString != null) { var doubleComaFields = targetUnitString.Separate(":"); if (doubleComaFields != null) { targetUnitString = doubleComaFields.Item1; targetExtraUnitString = doubleComaFields.Item2; } } var unit = UnitService.Parse(unitString); string inputUnit = unit.UnitElement.Name; string outputUnit = null; if (targetUnitString != null) { var targetUnit = UnitService.Parse(targetUnitString); UnitValue <ScalarFloat, float> targetExtraUnit = null; if (targetExtraUnitString != null) { targetExtraUnit = UnitService.Parse(targetExtraUnitString); } var result = UnitService.Convert(UnitService.Divide(unit, targetUnit)); string resultAsString = null; string targetUnitAsString = null; if (result.UnitElement.GetDimension().QuantityCount == 0) { resultAsString = result.Value.Value.ToString(); } else { if (targetExtraUnit != null) { result = UnitService.Convert(result, targetExtraUnit); } outputUnit = result.UnitElement.Name; resultAsString = "({0})".FormatWith(result.AsString); } if (targetUnit.Value.Value == targetUnit.Value.GetNeutral().Value) { targetUnitAsString = targetUnit.UnitElement.AsString; } else { targetUnitAsString = "({0})".FormatWith(targetUnit.AsString); } if (targetUnit.UnitElement.GetDimension().QuantityCount != 0) { if (outputUnit == null) { outputUnit = targetUnit.UnitElement.Name; } else { outputUnit = "{0} x {1}".FormatWith(outputUnit, targetUnit.UnitElement.Name); } } output = "{0} {1}".FormatWith(resultAsString, targetUnitAsString); } else { var result = UnitService.Convert(unit); if (result.UnitElement.GetDimension().QuantityCount == 0 && result.Value.Value == 1) { output = null; } else { output = result.AsString; if (result.UnitElement.GetDimension().QuantityCount != 0) { outputUnit = result.UnitElement.Name; } } } if (outputUnit != null) { title = "{0} ( {1} -> {2} )".FormatWith(title, inputUnit, outputUnit); } else { title = "{0} ( {1} -> )".FormatWith(title, inputUnit); } } catch (Exception ex) { title = "Exception !"; output = ex.Message; } return(new Tuple <string, string>(title, output)); }