コード例 #1
0
ファイル: ch09-1.cs プロジェクト: takwas/niit
        //Method to search a particular record on the basis of the date.
        public void Search()
        {
            string   Str, Chkstr1, Chkstr2;
            DateTime DD; int Pos;

            F = new FileStream("MyFIle.txt", FileMode.Open, FileAccess.Read);
            R = new StreamReader(F);
            Console.Write("Enter Date (MM/DD/YY): ");
            DD = Convert.ToDateTime(Console.ReadLine());

            //Code to fetch the data from the file and diplay it on the console in a proper format.
            while ((Str = R.ReadLine()) != null)
            {
                Chkstr1 = "Date: " + DD.ToShortDateString();
                Pos     = Str.IndexOf("?");
                Chkstr2 = Str.Substring(0, Pos);

                if ((Chkstr1.CompareTo(Chkstr2)) == 0)
                {
                    while (true)
                    {
                        Pos = Str.IndexOf("?");
                        if (Pos == -1)
                        {
                            break;
                        }
                        Console.WriteLine(Str.Substring(0, Pos));
                        Str = Str.Substring(Pos + 1);
                    }
                    Pos = 0;
                }
            }
            R.Close();
        }