public static bool HasPrefix(string value, out string prefix) { BinaryPrefixes i = BinaryPrefixes.Instance; prefix = ""; bool hasPrefix = (value != null && value.Length >= 2 && prefixes.ContainsKey(value.Trim().Substring(0, 2))); if (hasPrefix) { prefix = value.Trim().Substring(0, 2); } return(hasPrefix); }
public StandardUnit(string value) { //--------------------------// //--- Extract the prefix ---// //--------------------------// string prefix; if (!BinaryPrefixes.HasPrefix(value, out prefix)) { MetricPrefixes.HasPrefix(value, out prefix); } Prefix = prefix; Unit = value.Substring(Prefix.Length); var rgx = new Regex(PATTERN); if (!rgx.Match(Unit).Success) { Prefix = null; Unit = null; } }
public static StandardUnitPrefix GetPrefix(string prefix) { BinaryPrefixes i = BinaryPrefixes.Instance; return(prefixes.ContainsKey(prefix) ? prefixes[prefix] : null); }