示例#1
0
        /// <summary>
        /// Convert Dec string to UInt16Array.
        /// </summary>
        /// <param name="str">dec string. For example: "12333 12334" or "23333,12331"</param>
        /// <returns></returns>
        public static UInt16Array FromString(string str)
        {
            str = str.Trim();
            UInt16Array Arr = new UInt16Array();

            if (str != string.Empty)
            {
                string[] s = str.Split(new char[] { ',', ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < s.Length; i++)
                {
                    try
                    {
                        if (s[i] != string.Empty)
                        {
                            Arr.Add(Convert.ToUInt16(s[i], 10));
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(Arr);
        }
示例#2
0
        /// <summary>
        /// Convert Hex string to UInt16Array.
        /// </summary>
        /// <param name="str">Hex string. For example: "EEFFEEFF" or "EEFF EEFF" or "EEFF,EEFF"</param>
        /// <returns></returns>
        public static UInt16Array FromHexString(string str)
        {
            str = str.Trim();
            UInt16Array Arr = new UInt16Array();

            if (str != string.Empty)
            {
                string[] s = Util.SplitString(str, new char[] { ',', ' ', '\t', '\n', '\r' }, 4);
                for (int i = 0; i < s.Length; i++)
                {
                    try
                    {
                        if (s[i] != string.Empty)
                        {
                            Arr.Add(Convert.ToUInt16(s[i], 16));
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(Arr);
        }