ATMLModelLibrary.model.BinaryPrefixes.HasPrefix C# (CSharp) Method

HasPrefix() public static method

public static HasPrefix ( string value, string &prefix ) : bool
value string
prefix string
return bool
        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;
        }

Usage Example

Example #1
0
        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;
            }
        }