示例#1
0
        static void Main(string[] args)
        {
            GenerateRandomString.CreateFile(1000, GenerateRandomString.GenerateType.Numeric, 5);
            string f          = GenerateRandomString.FileName.GeneratedFilePath;
            var    fileStream = new FileStream(f, FileMode.Open, FileAccess.Read);

            using (var reader = new StreamReader(fileStream, Encoding.UTF8))
            {
                FileInfo info       = new FileInfo(f);
                long     fileLength = f.Length;
                Console.WriteLine(fileLength);
            }
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            //generate a file with 30,000 random strings containing up to 20 random keystrokes from the keyboard
            GenerateRandomString.CreateFile(30000, GenerateRandomString.GenerateType.AllKeys, 20);
            string f    = GenerateRandomString.FileName.GeneratedFilePath;
            var    list = FileSize.FileReader.FileReaderInit(f);

            foreach (var line in list)
            {
                //the below list of characters should be converted into their index if the character is found in the string
                var hiddenList = new List <char>()
                {
                    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'
                };
                var hiddenDigits = new List <int>();
                var designate    = line.ToCharArray();
                //go through each character in line
                foreach (var letter in designate)
                {
                    //if the character is in the list of hidden characters, add the index of the characters
                    if (hiddenList.Contains(letter))
                    {
                        hiddenDigits.Add(hiddenList.IndexOf(letter));
                    }
                    //if the character is a digit, leave the character where it is
                    if (IsDigit(letter))
                    {
                        hiddenDigits.Add(Convert.ToInt32(GetNumericValue(letter)));
                    }
                }
                //if there were no hiddenDigits or numbers, print NULL
                if (hiddenDigits.Count == 0)
                {
                    Console.WriteLine("NULL");
                }
                //otherwise, print the string of numbers generated from the existing numbers and hidden digits
                else
                {
                    var builder = new StringBuilder();
                    foreach (var digit in hiddenDigits)
                    {
                        builder.Append(digit).Append("");
                    }
                    Console.WriteLine(builder.ToString());
                }
            }
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //generate a file that contains two random numbers up to 4 characters in length
            GenerateRandomString.CreateFile(2, GenerateRandomString.GenerateType.Numbers, 4);
            string        f       = GenerateRandomString.FileName.GeneratedFilePath;
            List <int>    intList = new List <int>();
            List <string> list    = FileSize.FileReader.FileReaderInit(f);

            foreach (var line in list)
            {
                intList.Add(Convert.ToInt32(line));
            }
            //sum up the list of integers
            int total = intList.Sum();

            //print the sum of the integers
            Console.WriteLine(total);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //generate a file with 1000 random strings that are up to 5 digits in length
            GenerateRandomString.CreateFile(1000, GenerateRandomString.GenerateType.Numeric, 5);
            var f    = GenerateRandomString.FileName.GeneratedFilePath;
            var list = FileSize.FileReader.FileReaderInit(f);

            foreach (var line in list)
            {
                string[] bigDigits = { string.Empty };
                string[] printLine = { string.Empty };
                var      preParse  = line.ToCharArray();
                //for each character in the character array of the line of numbers
                foreach (var digit in preParse)
                {
                    //ignoring any character that isn't a number
                    if (IsDigit(digit))
                    {
                        //convert the character into an int
                        var digitInt = Convert.ToInt32(GetNumericValue(digit));
                        //pass the character into the Conversion method (see below)
                        bigDigits = ConvertToBigDigits(digitInt);
                    }
                    //create array of the size of the bigDigit's array
                    Array.Resize(ref printLine, bigDigits.Length);
                    //join the bigDigits array to the printLine array in order to print each of lines correctly for all of the characters
                    for (var i = 0; i < bigDigits.Length; i++)
                    {
                        printLine[i] += string.Join(printLine[i], bigDigits[i]);
                    }
                }
                //print each of the lines for each of the digits
                foreach (var t in printLine)
                {
                    Console.WriteLine(t);
                }
            }
            Console.ReadLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            //generate a file with 30,000 randomly generated numbers up to 6 characters in length
            GenerateRandomString.CreateFile(30000, GenerateRandomString.GenerateType.Numbers, 6);
            string f    = GenerateRandomString.FileName.GeneratedFilePath;
            var    list = FileSize.FileReader.FileReaderInit(f);

            foreach (var line in list)
            {
                //convert the string of numbers into an int
                int inputLine = Convert.ToInt32(line);
                //if the number is even (mod 2 = 0), print 1
                if (inputLine % 2 == 0)
                {
                    Console.WriteLine("1");
                }
                //if the number is odd (mod 2 = 1), print 0
                else
                {
                    Console.WriteLine("0");
                }
            }
            Console.ReadLine();
        }