当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.ReadLine方法代码示例

本文整理汇总了C#中System.IO.StreamReader.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.ReadLine方法的具体用法?C# StreamReader.ReadLine怎么用?C# StreamReader.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.ReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadStudentsInfoFromFile

        private static void ReadStudentsInfoFromFile(string filePath, SortedDictionary<string, SortedSet<Student>> courses)
        {
            using (StreamReader reader = new StreamReader(filePath))
            {
                string line = reader.ReadLine();
                while (line != string.Empty && line != null)
                {
                    string[] data = line.Split('|');
                    string firstName = data[0].Trim();
                    string lastName = data[1].Trim();
                    string courseName = data[2].Trim();

                    if (courses.ContainsKey(courseName))
                    {
                        courses[courseName].Add(new Student(firstName, lastName));
                    }
                    else
                    {
                        courses[courseName] = new SortedSet<Student>();
                        courses[courseName].Add(new Student(firstName, lastName));
                    }

                    line = reader.ReadLine();
                }
            }
        }
开发者ID:dchakov,项目名称:Data-Structures-and-Algorithms_HW,代码行数:26,代码来源:StartUp.cs

示例2: Read

        /// Read long numbers and initialize parameters
        /// A0 - The right particle of the first part of the number
        /// A1 - The left particle of the first part of the number
        /// B0 - The right particle of the second part of the number
        /// B1 - The left particle of the second part of the number
        /// K - Middle of the numbers
        /// N - Number of bits
        public static void Read(out BigInteger A0, out BigInteger A1,
                                out BigInteger B0, out BigInteger B1,
                                out int K, out int N)
        {
            using (StreamReader sr = new StreamReader("test.txt"))
            {
                string a, a0, a1, b, b0, b1;
                a = sr.ReadLine();
                b = sr.ReadLine();

                K = a.Length / 2;
                N = a.Length;

                // making strings to parse
                a0 = a.Substring(0, K);
                a1 = a.Substring(K);
                b0 = b.Substring(0, K);
                b1 = b.Substring(K);

                A0 = BigInteger.Parse(a1);
                A1 = BigInteger.Parse(a0);
                B0 = BigInteger.Parse(b1);
                B1 = BigInteger.Parse(b0);
            }

        }
开发者ID:SerKalayder,项目名称:Csharp-code,代码行数:33,代码来源:Program.cs

示例3: BoxInfo

        public BoxInfo(int clientID, string fileName)
        {
            StreamReader sr = new StreamReader(fileName);

            sr.ReadLine();// burn the headings

            for (int x = 0; x < 28; x++)
            {
                myCompartments[x] = new Compartment();
            }

            string[] dataLine;

            while (!sr.EndOfStream)
            {
                dataLine = sr.ReadLine().Split(',');
                int curID = int.Parse (dataLine[0].Trim());

                if (curID == clientID)
                { //this dataline is for this client
                    int compartmentNum = int.Parse(dataLine[1]);
                    int hour = int.Parse(dataLine[2]);
                    int minute = int.Parse(dataLine[3]);
                    string pills = dataLine[4].Trim();
                    myCompartments[compartmentNum-1].hour = hour;
                    myCompartments[compartmentNum-1].minute = minute;
                    myCompartments[compartmentNum-1].pills = pills;
                }
           
            }


        }
开发者ID:syu6882,项目名称:PillBot,代码行数:33,代码来源:BoxInfo.cs

示例4: CarregarInformacoesLoginServidor

        /// <summary>
        /// Carrega as informações do arquivo de configuração do E-mail.
        /// </summary>
        /// <returns></returns>
        public static Email CarregarInformacoesLoginServidor()
        {
            Cryptor cr;
            string CaminhoDoArquivo = String.Format("{0}/Email.dat", Ferramentas.ObterCaminhoDoExecutavel());
            Email EmailBase = new Email();
            StreamReader sr = null;
            cr = new Cryptor("[email protected]$$w0rd");

            try
            {
                sr = new StreamReader(CaminhoDoArquivo);

                EmailBase.email = cr.Decrypt(sr.ReadLine());
                EmailBase.Senha = cr.Decrypt(sr.ReadLine());
                EmailBase.Host = cr.Decrypt(sr.ReadLine());
                EmailBase.Port = int.Parse(cr.Decrypt(sr.ReadLine()));
            }
            catch (System.Exception exc)
            {
                ControllerArquivoLog.GeraraLog(exc);
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }
            return EmailBase;
        }
开发者ID:CristianoRC,项目名称:SoftwareOrdemDeServico,代码行数:32,代码来源:ControllerEmail.cs

示例5: ExecuteCommands

        private static void ExecuteCommands()
        {
            var reader = new StreamReader("..//..//Commands.txt");
            string line = reader.ReadLine();
            using (reader)
            {
                while (line != null)
                {
                    string[] data =
                        line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();

                    var commandName = data[0];
                    if (commandName.ToLower() == "find")
                    {
                        Console.WriteLine(
                            "The command 'find' with parameters {0} returned the following results:",
                            data.Length == 3 ? string.Join(",", new[] { data[1], data[2] }) : data[1]);
                        if (data.Length == 3)
                        {
                            var result = book.Find(data[1], data[2]);
                            Console.WriteLine(string.Join("\n", result));
                        }
                        else
                        {
                            Console.WriteLine(string.Join("\n", book.Find(data[1])));
                        }
                    }
                    line = reader.ReadLine();
                }
            }
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:31,代码来源:Program.cs

示例6: Run

        public void Run()
        {
            using (var reader = new StreamReader("jobs.txt"))
            using (var writer = new StreamWriter("output.txt"))
            {
                var jobs = new List<Job>();
                reader.ReadLine();
                while (true)
                {
                    string row = reader.ReadLine();
                    if (row == null)
                    {
                        break;
                    }

                    var parts = row.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    var numbers = parts.Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();
                    jobs.Add(new Job(numbers[0], numbers[1]));
                }

                var weightedSum1 = JobScheduler.GetWeightedSumOfCompletionTimes(jobs, JobScheduler.CompareByDifference);
                writer.WriteLine(weightedSum1);

                var weightedSum2 = JobScheduler.GetWeightedSumOfCompletionTimes(jobs, JobScheduler.CompareByRatio);
                writer.WriteLine(weightedSum2);
            }
        }
开发者ID:korzenikov,项目名称:Projects,代码行数:27,代码来源:JobSchedulerTask.cs

示例7: LoadPath

        public static List<Path> LoadPath()
        {
            Path pathToLoad = new Path();
            List<Path> pathsList = new List<Path>();

            using (StreamReader reader = new StreamReader(@"..\..\LoadPaths.txt"))
            {
                string newLine = reader.ReadLine();                

                while (newLine != string.Empty)
                {
                    Point3D newPoint = new Point3D();
                    newLine = reader.ReadLine();
                    
                    newPoint.X = int.Parse(newLine);
                    newLine = reader.ReadLine();
                    newPoint.Y = int.Parse(newLine);
                    newLine = reader.ReadLine();
                    newPoint.Z = int.Parse(newLine);

                    pathToLoad.AddPoint(newPoint);
                    newLine = reader.ReadLine();
                    
                    pathsList.Add(pathToLoad);
                    pathToLoad = new Path();
                    
                    
                }
            }

            return pathsList;
        }
开发者ID:Cecosam,项目名称:Csharp-Projects,代码行数:32,代码来源:PathStorage.cs

示例8: Load

        // Load an array of training set items from the csv file
        public static List<TrainingItem> Load(string csvFile)
        {
            List<TrainingItem> trainingItems = new List<TrainingItem>();
            string line;
            string[] items;

            // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader(csvFile);

            // Skip the first line since it is the header
            file.ReadLine();

            while ((line = file.ReadLine()) != null)
            {
                TrainingItem trainingItem = new TrainingItem();
                items = line.Split(',');
                trainingItem.FileName = items[0];
                trainingItem.Label = items[1];
                trainingItems.Add(trainingItem);
            }

            file.Close();

            return trainingItems;
        }
开发者ID:nagyist,项目名称:FaceRecognition-csharp,代码行数:26,代码来源:TrainingItem.cs

示例9: Main

        private static void Main()
        {
            var fileOne = new StreamReader(@"..\..\fileOne.txt");
            var fileTwo = new StreamReader(@"..\..\fileTwo.txt");

            using (fileOne)
            {
                using (fileTwo)
                {
                    var fileOneLine = fileOne.ReadLine();
                    var fileTwoLine = fileTwo.ReadLine();
                    var currentLine = 0;
                    var matchingLines = 0;

                    while (fileOneLine != null || fileTwoLine != null)
                    {
                        currentLine++;
                        if (fileTwoLine == fileOneLine)
                        {
                            matchingLines++;
                        }

                        fileOneLine = fileOne.ReadLine();
                        fileTwoLine = fileTwo.ReadLine();
                    }

                    Console.WriteLine(
                        "There are {0} line(s) that are the same and {1} that are different",
                        matchingLines,
                        currentLine - matchingLines);
                }
            }
        }
开发者ID:NikolaPineda,项目名称:Telerik,代码行数:33,代码来源:Program.cs

示例10: CMusicHit

        public CMusicHit(String path)
        {
            int counter = 0;
            this._next = 0;
            string line;
            StreamReader hitFile = new StreamReader(path);

            line = hitFile.ReadLine();
            this._length = int.Parse(line);
            line = hitFile.ReadLine();
            this._speed = int.Parse(line);
            line = hitFile.ReadLine();
            this._endTime = int.Parse(line);

            this._time = new int[this._length];
            this._position = new int[this._length];
            while ((line = hitFile.ReadLine()) != null) {
                if (line.Contains('t'))
                {
                    line = line.Substring(line.IndexOf(':')+1);
                    this._time[counter] = int.Parse(line);
                }
                else {
                    line = line.Substring(line.IndexOf(':')+1);
                    this._position[counter] = int.Parse(line);
                    counter++;
                }
            }
        }
开发者ID:lantian2012,项目名称:3DS-GuitarHero,代码行数:29,代码来源:CMusicHit.cs

示例11: Main

        static void Main(string[] args)
        {
             using (StreamReader orig = new StreamReader("orig.txt"))
            {
                int lineNumber = 0;
                string line = orig.ReadLine();

                while (line != null)
                {
                    lineNumber++;
                    if (lineNumber % 2 == 0)
                    {
                        StreamWriter even = new StreamWriter("even.txt", true);
                        {
                            even.WriteLine(line);
                        } even.Close();
                    }
                    else
                    {
                        StreamWriter odd = new StreamWriter("odd.txt", true);
                        {
                            odd.WriteLine(line);
                        } odd.Close();
                    }
                    line = orig.ReadLine();
                }
            }
            Console.WriteLine("Your text is separated by even and odd lines in two separated files.");
            Console.WriteLine("Check your folder to see the result!");
            Console.WriteLine();
        }
开发者ID:rady1990,项目名称:homework,代码行数:31,代码来源:Program.cs

示例12: fetchServers

 /// <summary>
 /// Fetches the list of servers and adds them to serverView's server collection
 /// </summary>
 public void fetchServers()
 {
     WebRequest serverReq = WebRequest.Create("http://kaillera.com/raw_server_list2.php?version=0.9");
     WebResponse serverResp = serverReq.GetResponse();
     using (StreamReader sr = new StreamReader(serverResp.GetResponseStream()))
     {
         while (!sr.EndOfStream)
         {
             try
             {
                 Server currServer = new Server();
                 currServer.name = sr.ReadLine();
                 string[] servInfo = sr.ReadLine().Split(';');
                 string[] ipPort = servInfo[0].Split(':');
                 currServer.ip = IPAddress.Parse(ipPort[0]);
                 currServer.port = int.Parse(ipPort[1]);
                 currServer.users = int.Parse(servInfo[1].Split('/')[0]);
                 currServer.numGames = int.Parse(servInfo[2]);
                 currServer.version = servInfo[3];
                 currServer.location = servInfo[4];
                 addServers(currServer);
             }
             catch (Exception)
             {
                 log.Warn("Invalid server detected!");
             }
         }
     }
 }
开发者ID:eisenbe7,项目名称:KailleraNet,代码行数:32,代码来源:MasterServerList.cs

示例13: Read

        public Read(Stream myStream)
        {
            string aux;
            string[] pieces;

            //read the file line by line
            StreamReader sr = new StreamReader(myStream);
            aux = sr.ReadLine();
            header = aux.Split(',');
            nColumns = header.Length;
            nLines = 0;
            while ((aux = sr.ReadLine()) != null)
            {
                if (aux.Length > 0) nLines++;
            }

            //read the numerical data from file in an array
            data = new float[nLines, nColumns];
            sr.BaseStream.Seek(0, 0);
            sr.ReadLine();
            for (int i = 0; i < nLines; i++)
            {
                aux = sr.ReadLine();
                pieces = aux.Split(',');
                for (int j = 0; j < nColumns; j++) data[i, j] = float.Parse(pieces[j]);
            }
            sr.Close();
        }
开发者ID:amal-roshan,项目名称:GraphDemo1,代码行数:28,代码来源:Read.cs

示例14: Main

 static void Main(string[] args)
 {
     string fileName1 = @"..\..\file1.txt";
     string fileName2 = @"..\..\file2.txt";
     StreamReader reader1 = new StreamReader(fileName1);
     StreamReader reader2 = new StreamReader(fileName2);
     int countEqual = 0;
     int countDifferent = 0;
     string line1 = reader1.ReadLine();
     string line2 = reader2.ReadLine();
     while (line1 != null)
     {
         if (line1 == line2)
         {
             countEqual++;
         }
         else
         {
             countDifferent++;
         }
         line1 = reader1.ReadLine();
         line2 = reader2.ReadLine();
     }
     reader1.Close();
     reader2.Close();
     Console.WriteLine("Equal lines number -> {0}", countEqual);
     Console.WriteLine("Different lines number -> {0}", countDifferent);
 }
开发者ID:kizisoft,项目名称:TelerikAcademy,代码行数:28,代码来源:CompareTextFiles.cs

示例15: Main

        static void Main()
        {
            StreamWriter writerFirst = new StreamWriter(@"..\..\test.txt",false);
            using (writerFirst)
            {
                StreamReader readFirstDoc = new StreamReader(@"..\..\Concat.cs"); //The first document is the Concat.cs.
                using (readFirstDoc)
                {
                    string lineDoc1 = readFirstDoc.ReadLine();
                        while(lineDoc1!=null)
                        {
                            writerFirst.WriteLine(lineDoc1);
                            lineDoc1=readFirstDoc.ReadLine();
                        }
                }
                
            }
            StreamWriter writerSecond = new StreamWriter(@"..\..\test.txt", true);
            using(writerSecond)
            {
                StreamReader readSecondDoc = new StreamReader(@"..\..\App.config"); //The second document is App.config
                using (readSecondDoc)
                {

                    string lineDoc2 = readSecondDoc.ReadLine();
                    while (lineDoc2 != null)
                    {
                        writerSecond.WriteLine(lineDoc2);
                        lineDoc2 = readSecondDoc.ReadLine();
                    }
                }
            }
            Console.WriteLine("Concatenation finished!");
        }
开发者ID:peterlambov,项目名称:CSharp,代码行数:34,代码来源:Concat.cs


注:本文中的System.IO.StreamReader.ReadLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。