Example #1
0
File: Types.cs Project: vorba/pv3
 public PhoneNumber(string phoneNumber)
 {
     //phoneNumber = phoneNumber == null ? "" : phoneNumber;
     if (phoneNumber == null)
     {
         return;
     }
     Number = new System.Text.RegularExpressions.Regex(@"[^\d]").Replace(phoneNumber, "");
     if (Number.Length == 10)
     {
         Area    = Number.Substring(0, 3);
         Nxx     = Number.Substring(3, 3);
         Station = Number.Substring(6, 4);
     }
 }
Example #2
0
        /// <summary>
        /// Returns a string containing a number represented in exponential notation.
        /// </summary>
        /// <returns></returns>
        public string ToExponential()
        {
            string raw_value_string = raw_value.ToString();
            int    decimalIndex;

            try
            {
                decimalIndex = raw_value_string.IndexOf('.') - 1;
            }
            catch (System.Exception)
            {
                decimalIndex = -2;
            }

            if (decimalIndex == -2)
            {
                decimalIndex = raw_value_string.Length - 1;
            }

            string raw_str = raw_value_string.Replace(".", "");
            string str     = new System.Text.RegularExpressions.Regex(@"^0+").Replace(raw_str, "");

            int eVal = raw_str.Length - str.Length + decimalIndex;

            return($"{str[0]}.{str.Substring(1)}e{(eVal < 0 ? "-" : "+")}{eVal}");
        }
Example #3
0
        /// <summary>
        /// Returns a string containing a number represented in exponential notation.
        /// </summary>
        /// <param name="fractionDigits">Number of digits after the decimal point.</param>
        /// <returns></returns>
        public string ToExponential(Number fractionDigits)
        {
            string raw_value_string = raw_value.ToString();
            int    decimalIndex;

            try
            {
                decimalIndex = raw_value_string.IndexOf('.') - 1;
            }
            catch (System.Exception)
            {
                decimalIndex = -2;
            }

            if (decimalIndex == -2)
            {
                decimalIndex = raw_value_string.Length - 1;
            }

            string raw_str = raw_value_string.Replace(".", "");
            string str     = new System.Text.RegularExpressions.Regex(@"^0+").Replace(raw_str, "");

            int    eVal   = raw_str.Length - str.Length + decimalIndex;
            string digits = $"{str.Substring(1)}";

            for (int index = 0, length = (fractionDigits - digits.Length).ToInt(); index < length; index++)
            {
                digits += "0";
            }
            digits = digits.Substring(0, fractionDigits.ToInt());

            return($"{str[0]}{(digits.Length > 0 ? $".{digits}" : "")}e{(eVal < 0 ? "-" : "+")}{eVal}");
        }
        private static List <string> GetTheMatches(string inputStr)
        {
            List <string> retval = new List <string>();

            int[] lengths = new int[] { 7, 8 };
            for (int i = 0; i < lengths.Length; i++)
            {
                string tmp = new System.Text.RegularExpressions.Regex("(\\d{" + lengths[i] + ",})").Match(inputStr.ToString()).ToString();
                while (tmp.Length >= lengths[i])
                {
                    retval.Add(tmp.Substring(0, lengths[i]));
                    tmp = tmp.Remove(0, 1);
                }
            }
            return(retval);
        }
Example #5
0
        public static string BuildAccountHash(string ssn, string firstName, string lastName, string state) {
            ssn = new System.Text.RegularExpressions.Regex(
                "[^0-9]",
                System.Text.RegularExpressions.RegexOptions.Compiled
            ).Replace(ssn, "");

            ssn = ssn.Substring(3, 6);

            var buffer = new StringBuilder();
            buffer.Append(ssn);
            buffer.Append(lastName.Trim().ToLower());
            buffer.Append(firstName.Trim().ToLower()[0]);
            buffer.Append(state.Trim().ToLower());
            var input = buffer.ToString();
            var output = AOI.Crypto.Hash.SHA1(input);
            return output;
        }
Example #6
0
        private static List <string> GetTheMatches(string inputStr)
        {
            List <string> retval = new List <string>();
            string        tmp    = new System.Text.RegularExpressions.Regex("(\\d{7,})").Match(inputStr.ToString()).ToString();

            while (tmp.Length >= 7)
            {
                retval.Add(tmp.Substring(0, 7));
                tmp = tmp.Remove(0, 1);
            }
            tmp = new System.Text.RegularExpressions.Regex("(\\d{8,})").Match(inputStr.ToString()).ToString();
            while (tmp.Length >= 8)
            {
                retval.Add(tmp.Substring(0, 8));
                tmp = tmp.Remove(0, 1);
            }
            return(retval);
        }
Example #7
0
        public static List <string> Read()
        {
            string        datastr = DateTime.Today.ToString("yyyyMMdd");
            List <string> strlist = new List <string>();
            string        path    = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            StreamReader  sr      = new StreamReader(path + @"\" + datastr + " 资金股份查询.txt", Encoding.Default);
            String        line;
            int           i = 0;

            while ((line = sr.ReadLine()) != null)
            {
                i++;
                if (i > 4)
                {
                    var str = new System.Text.RegularExpressions.Regex("[\\s]+").Replace(line.ToString(), "|");
                    str = str.Substring(0, str.Length);
                    strlist.Add(str);
                }

                Console.WriteLine(i + " " + line.ToString());
            }
            return(strlist);
        }
Example #8
0
        private UpLoadFileResult UpLoadPicture(System.IO.Stream file, string dirPath, string fileName = "")
        {
            UpLoadFileResult upLoadFileResult = new UpLoadFileResult();
            string           encodingName     = "utf-8";
            string           imgType          = string.Empty;
            List <string>    typeList         = new List <string>()
            {
                "JPG", "BMP", "PNG", "JPEG"
            };

            using (MemoryStream ms = new MemoryStream())
            {
                file.CopyTo(ms);
                ms.Position = 0;

                var encoding     = Encoding.GetEncoding(encodingName);
                var reader       = new StreamReader(ms, encoding);
                var headerLength = 0L;

                //读取第一行
                var firstLine = reader.ReadLine();
                //计算偏移(字符串长度+回车换行2个字符)
                headerLength += encoding.GetBytes(firstLine).LongLength + 2;

                //读取第二行
                var secondLine = reader.ReadLine();
                //计算偏移(字符串长度+回车换行2个字符)
                headerLength += encoding.GetBytes(secondLine).LongLength + 2;
                //解析文件名
                string orgFileName = new System.Text.RegularExpressions.Regex("filename=\"(?<fn>.*)\"").Match(secondLine).Groups["fn"].Value;
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = orgFileName;
                }
                else
                {
                    fileName = orgFileName.Replace(orgFileName.Substring(0, orgFileName.LastIndexOf('.')), fileName);
                }
                //判断图片格式
                imgType = fileName.Substring(fileName.LastIndexOf('.') + 1).ToUpper();
                if (!typeList.Contains(imgType))
                {
                    upLoadFileResult.FileName = "errorType";
                    upLoadFileResult.success  = false;
                    return(upLoadFileResult);
                }
                //一直读到空行为止
                while (true)
                {
                    //读取一行
                    var line = reader.ReadLine();
                    //若到头,则直接返回
                    if (line == null)
                    {
                        break;
                    }
                    //若未到头,则计算偏移(字符串长度+回车换行2个字符)
                    headerLength += encoding.GetBytes(line).LongLength + 2;
                    if (line == "")
                    {
                        break;
                    }
                }

                //设置偏移,以开始读取文件内容
                ms.Position = headerLength;
                ////减去末尾的字符串:“/r/n--/r/n”
                ms.SetLength(ms.Length - encoding.GetBytes(firstLine).LongLength - 3 * 2);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                string path = Path.Combine(dirPath, fileName);
                using (FileStream fileToupload = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    ms.CopyTo(fileToupload);
                    fileToupload.Flush();
                }
                upLoadFileResult.FileName = fileName;
                upLoadFileResult.success  = true;
            }
            return(upLoadFileResult);
        }