示例#1
0
        static List <PasswordLine> ParsePasswords(string path)
        {
            List <PasswordLine> lines = new List <PasswordLine>();

            using (StreamReader sr = File.OpenText(path))
            {
                string s = String.Empty;
                while ((s = sr.ReadLine()) != null)
                {
                    var line = new PasswordLine();

                    int  num = 0;
                    int  i   = 0;
                    char c   = s[i];
                    while (c != '-')
                    {
                        num = num * 10 + (c - '0');
                        c   = s[++i];
                    }
                    line.min = num;

                    num = 0;
                    c   = s[++i];
                    while (c != ' ')
                    {
                        num = num * 10 + (c - '0');
                        c   = s[++i];
                    }
                    line.max = num;

                    line.c = s[++i];

                    line.password = s.Substring(i + 3);
                    lines.Add(line);
                }
            }
            return(lines);
        }
示例#2
0
        static List <PasswordLine> ParsePasswordsRegex(string path)
        {
            List <PasswordLine> passwords = new List <PasswordLine>();
            Regex re = new Regex(@"(?<min>\d+)-(?<max>\d+) (?<char>\w): (?<password>.*)", RegexOptions.Compiled);
            int   i  = 0;

            using (StreamReader sr = File.OpenText(path))
            {
                string s = String.Empty;
                while ((s = sr.ReadLine()) != null)
                {
                    var match    = re.Match(s);
                    var password = new PasswordLine();
                    password.min      = match.GetInt("min");
                    password.max      = match.GetInt("max");
                    password.c        = match.Groups["char"].ToString()[0];
                    password.password = match.Groups["password"].ToString();
                    passwords.Add(password);
                    i++;
                }
            }
            return(passwords);
        }