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


C# StreamReader.Peek方法代码示例

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


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

示例1: ReadRecords

        private IEnumerable<Record> ReadRecords(string fileName)
        {
            var stringBuilder = new StringBuilder();

            using (var reader = new StreamReader(fileName))
            {
                ReadOnlyCollection<string> header;
                if (reader.Peek() >= 0)
                {
                    var first = this.ParseLine(reader.ReadLine(), stringBuilder).ToArray();

                    header = new ReadOnlyCollection<string>(first);
                }
                else
                {
                    yield break;
                }

                for (var i = 0; i < this._numberRecordsToSkip && reader.Peek() >= 0; i++)
                {
                    reader.ReadLine();
                }

                while (reader.Peek() >= 0)
                {
                    var items = this.ParseLine(reader.ReadLine(), stringBuilder).ToArray();

                    yield return new Record(header, items);
                }
            }
        }
开发者ID:modulexcite,项目名称:Tx,代码行数:31,代码来源:CsvObservable.cs

示例2: ReadAll

 public virtual List<student> ReadAll(string fileName)
 {
     FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
     StreamReader sr = new StreamReader(file);
     List<student> result = new List<student>();
     if (Indexed)
     {
         FileStream fs = new FileStream("Index.txt", FileMode.Open, FileAccess.Read);
         StreamReader Sr = new StreamReader(fs);
         if (Sr.Peek() != -1)
             CurrentIndexVal1 = int.Parse(Sr.ReadLine());
         while (Sr.Peek() != -1)
         {
             CurrentIndexVal2 = int.Parse(Sr.ReadLine());
             student std = this.Read(sr);
             result.Add(std);
             CurrentIndexVal1 = CurrentIndexVal2;
         }
     }
     else
     {
         while (sr.Peek() != -1)
         {
             student std = this.Read(sr);
             result.Add(std);
         }
     }
     sr.Close();
     return result;
 }
开发者ID:Mennat-Ullah,项目名称:File-Structures-Task,代码行数:30,代码来源:RecordStructure.cs

示例3: AddCurrentRow

 public static void AddCurrentRow(int oneChar, StreamReader DataStream)
 {
     if (oneChar == 10 && DataStream.Peek() == 13) { DataStream.Read(); }
     else if (oneChar == 13 && DataStream.Peek() == 10) { DataStream.Read(); }
     CurrentRow += 1;
     CurrentColumn = 0;
 }
开发者ID:JackTing,项目名称:ifctoolkit,代码行数:7,代码来源:SLexer.cs

示例4: CsvToDt

        /// <summary>
        /// 将Csv读入DataTable
        /// </summary>
        /// <param name="filePath">csv文件路径</param>
        /// <param name="n">表示第n行是字段title,第n+1行是记录开始</param>
        public static DataTable CsvToDt(string filePath, int n)
        {
            DataTable dt = new DataTable();
            StreamReader reader = new StreamReader(filePath, System.Text.Encoding.UTF8, false);
            int i = 0;
            int m = 0;
            reader.Peek();
            while (reader.Peek() > 0)
            {
                m = m + 1;
                string str = reader.ReadLine();
                if (m >= n + 1)
                {
                    string[] split = str.Split(',');

                    System.Data.DataRow dr = dt.NewRow();
                    for (i = 0; i < split.Length; i++)
                    {
                        dr[i] = split[i];
                    }
                    dt.Rows.Add(dr);
                }
            }
            return dt;
        }
开发者ID:GitWPeng,项目名称:Helper,代码行数:30,代码来源:CsvHelper.cs

示例5: Csv2DataTable

        /// <summary>
        ///     将CSV格式的流读入table
        /// </summary>
        /// <param name="ms">数据流</param>
        /// <param name="n">整型值</param>
        /// <returns>DataTable</returns>
        public static DataTable Csv2DataTable(MemoryStream ms, int n)
        {
            var dt = new DataTable();
            using (var reader = new StreamReader(ms))
            {
                int i = 0, m = 0;
                reader.Peek();
                while (reader.Peek() > 0)
                {
                    m = m + 1;
                    string str = reader.ReadLine();
                    if (m >= n + 1)
                    {
                        string[] split = str.Split(',');

                        DataRow dr = dt.NewRow();
                        for (i = 0; i < split.Length; i++)
                        {
                            dr[i] = split[i];
                        }
                        dt.Rows.Add(dr);
                    }
                }
                return dt;
            }
        }
开发者ID:kevin-h-wang,项目名称:MVCStudy,代码行数:32,代码来源:FICsvHelper.cs

示例6: ProcessDigit

        public static String ProcessDigit(int FirstCharactor, StreamReader DataStream)
        {
            StringBuilder theNumber = new StringBuilder();
            theNumber.Append((char)FirstCharactor);
            int peekedChar;
            //43 + 45 - 46 .
            while (((peekedChar = DataStream.Peek()) >= 48 && peekedChar <= 57)
                || peekedChar == 46)
            {
                theNumber.Append((char)DataStream.Read());
            }

            if (peekedChar == 69) // E
            {
                theNumber.Append((char)DataStream.Read());
                if ((peekedChar = DataStream.Peek()) == 43 || peekedChar == 45)
                {
                    theNumber.Append((char)DataStream.Read());
                }
                while ((peekedChar = DataStream.Peek()) >= 48 && peekedChar <= 57)
                {
                    theNumber.Append((char)DataStream.Read());
                }
            }
            return theNumber.ToString();
            //Console.WriteLine(theNumber);
        }
开发者ID:JackTing,项目名称:ifctoolkit,代码行数:27,代码来源:Lexer.cs

示例7: Split

        public void Split()
        {
            int split_num = 1;
            string destFilePart = Path.Combine(_opts.WorkingDirectory, string.Format(_opts.SplitFilePattern, split_num));
            StreamWriter sw = new StreamWriter(destFilePart);
            long read_line = 0;
            using (StreamReader sr = new StreamReader(_opts.InputFileName))
            {
                while (sr.Peek() >= 0)
                {

                    // Progress reporting
                    //if (++read_line % rowDivider == 0)
                    //    Console.Write("{0:f2}%   \r",
                    //      100.0 * sr.BaseStream.Position / sr.BaseStream.Length);

                    // Copy a line
                    sw.WriteLine(sr.ReadLine());

                    // If the file is big, then make a new split,
                    // however if this was the last line then don't bother
                    if (read_line / split_num > _opts.FileSizeDivider && sr.Peek() >= 0)
                    {
                        sw.Close();
                        destFilePart = Path.Combine(_opts.WorkingDirectory, string.Format(_opts.SplitFilePattern, split_num++));
                        sw = new StreamWriter(destFilePart);
                    }
                }
            }
            sw.Close();
        }
开发者ID:Zawulon,项目名称:mergesort,代码行数:31,代码来源:splitter.cs

示例8: ReadNumber

        private string ReadNumber(StreamReader FileReader)
        {
            string TempString = "";
            while ((FileReader.Peek() >= 0) && ((Char.IsNumber((char)FileReader.Peek()))
                || ((char)FileReader.Peek() == '.')))
            {

                TempString += (char)FileReader.Read();
            }
            if ((((char)FileReader.Peek()) == 'E') || (((char)FileReader.Peek()) == 'e'))
            {
                TempString += (char)FileReader.Read();
                while (Char.IsNumber((char)FileReader.Peek()))
                {
                    TempString += (char)FileReader.Read();
                }
                if ((((char)FileReader.Peek()) == '+') || (((char)FileReader.Peek()) == '-'))
                {
                    TempString += (char)FileReader.Read();
                    while (Char.IsNumber((char)FileReader.Peek()))
                    {
                        TempString += (char)FileReader.Read();
                    }

                }

            }
            return TempString;
        }
开发者ID:Denakol,项目名称:PerlMt,代码行数:29,代码来源:eReader.cs

示例9: LoadEntries

        public static List<Employee> LoadEntries()
        {
            List<Employee> list = null;

            try {
                using (FileStream fileStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) {
                    using (StreamReader reader = new StreamReader(fileStream)) {

                        //Populate List from lines in file
                        list = new List<Employee>();
                        while (reader.Peek() != -1) {
                            Employee employee = new Employee();

                            for (int i = 0; i <= 3; i++) {
                                string line;

                                if (reader.Peek() != -1) {
                                    line = reader.ReadLine();
                                } else {
                                    break;
                                }

                                switch (i) {
                                    case 0:
                                        employee.firstName = line;
                                        break;

                                    case 1:
                                        employee.lastName = line;
                                        break;

                                    case 2:
                                        employee.employeeID = Convert.ToInt32(line.Substring(2));
                                        break;

                                    case 3:
                                        employee.department = line;
                                        break;
                                }
                            }

                            list.Add(employee);

                            if (reader.Peek() != -1) {
                                reader.ReadLine();
                            }
                        }
                    }
                }
            } catch (FileNotFoundException) {
                MessageBox.Show("File not found: " + inputFile, "File Error");
            } catch (DirectoryNotFoundException) {
                MessageBox.Show("Directory not found: " + inputDir, "Directory Error");
            } catch (IOException ex) {
                MessageBox.Show(ex.GetType() + ": " + ex.Message, "IOException");
            }

            return list;
        }
开发者ID:NicholasLambell,项目名称:AS4_LinkListSort,代码行数:59,代码来源:FileHandler.cs

示例10: GetContactAccessor

 /// <summary>
 /// 从CSV文件总获取联系人的方法
 /// </summary>
 /// <param name="fileStream">CSV文件流</param>
 /// <returns>联系人字典</returns>
 public static Dictionary<string, string> GetContactAccessor(Stream fileStream)
 {
     System.IO.StreamReader reader = new System.IO.StreamReader(fileStream, Encoding.Default);
     Dictionary<string, string> contacts = new Dictionary<string, string>(); //存放读取出来的csv联系人
     //根据表头确定联系人的名字在什么地方。
     int lastNameIndex = -1;
     int firstNameIndex = -1;
     if (reader.Peek() > 0)
     {
         string contact = reader.ReadLine();
         contact = contact.Replace("\"", "");
         string[] contactArray = contact.Split(new char[] { ',' });
         for (int i = 0; i < contactArray.Length; i++)
         {
             if (string.IsNullOrEmpty(contactArray[i]))
                 continue;
             switch (contactArray[i].ToLower())
             {
                 case "姓名":
                     lastNameIndex = i;
                     break;
                 case "name":
                     lastNameIndex = i;
                     break;
                 case "名":
                     lastNameIndex = i;
                     break;
                 case "姓":
                     firstNameIndex = i;
                     break;
                 default:
                     break;
             }
         }
     }
     //循环获取联系人名和Email信息
     while (reader.Peek() > 0)
     {
         string contact = reader.ReadLine();
         contact = contact.Replace("\"", "");
         string[] contactArray = contact.Split(new char[] { ',' });
         string name = string.Empty;
         if (firstNameIndex != -1)
             name += contactArray[firstNameIndex];
         if (lastNameIndex != -1)
             name += contactArray[lastNameIndex];
         Regex regex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
         Match match = regex.Match(contact);
         string email = null;
         if (match.Success)
             email = match.Value;
         if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(name))
             contacts[email] = name;
     }
     return contacts;
 }
开发者ID:hbulzy,项目名称:SYS,代码行数:61,代码来源:CSVParser.cs

示例11: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Enter filepath to read from");
            var inputFile = Console.ReadLine();
            var inputFileName = string.IsNullOrWhiteSpace(inputFile) ? @"C:\users\vshardul\desktop\testRunEntries.txt" : inputFile;

            Console.WriteLine("Enter output filepath");
            var outputFile = Console.ReadLine();
            var outputFileName = string.IsNullOrWhiteSpace(outputFile) ? @"Output.txt" : outputFile;

            Console.WriteLine("Entries to ignore - ");
            var entriesToIgnore = long.Parse(Console.ReadLine());

            if (!File.Exists(inputFileName))
            {
                Console.WriteLine("Invalid input file path");
                return;
            }

            using (var inputStream = new StreamReader(inputFileName))
            {
                if (inputStream.Peek() < 0)
                {
                    Console.WriteLine("Enpty Stream");
                    return;
                }

                var headerRow = inputStream.ReadLine();

                int ignoreCount = 0;
                while (ignoreCount < entriesToIgnore && inputStream.Peek() >= 0)
                {
                    inputStream.ReadLine();
                    ignoreCount++;
                }

                using (var outputStream = new StreamWriter(outputFileName))
                {
                    outputStream.WriteLine(headerRow);
                    while (inputStream.Peek() >= 0)
                    {
                        var line = inputStream.ReadLine();
                        if (line != null && line.Split('\t').Length == headerRow.Split('\t').Length)
                        {
                            outputStream.WriteLine(line);
                        }
                    }

                    outputStream.Close();
                }

                inputStream.Close();
            }

            Console.WriteLine("File content trnafer successfull");
        }
开发者ID:vshardul,项目名称:RandomStuff,代码行数:56,代码来源:Program.cs

示例12: GetStreamDigits

 public int GetStreamDigits(StreamReader sr, int count=2)
 {
     char inp; string nums="";
     if(count<1||sr==null||sr.Peek()<0) return -1;
     while(nums.Length<count && sr.Peek()>=0) {
         do { inp=(char)sr.Read(); } while(!Char.IsDigit(inp) && sr.Peek()>=0);
         if(Char.IsDigit(inp)) nums+=inp;
     }
     return nums.Length>0?int.Parse(nums):-1;
 }
开发者ID:krowe,项目名称:MidiPi,代码行数:10,代码来源:PiBase.cs

示例13: ReadAndDecode

 public String ReadAndDecode(StreamReader sr)
 {
     String ts=sr.ReadLine();
     while((sr.Peek()==9)||(sr.Peek()==32))
     {
         sr.Read();
         ts=ts+'\r'+'\n'+sr.ReadLine();
     }
     return Decode(ts);
 }
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:10,代码来源:Encoding.cs

示例14: Formatting

		public void Formatting()
		{
			var o = DFormattingOptions.CreateDStandard();
			
			bool isTargetCode = false;
			
			var rawCode = string.Empty;
			var sb = new StringBuilder();
			var l = new List<Tuple<string,string>>();
			
			using(var st = Assembly.GetExecutingAssembly().GetManifestResourceStream("formatterTests")){
				using(var r = new StreamReader(st))
				{
					int n;
					while((n=r.Read()) != -1)
					{
						if((n == ':' && r.Peek() == ':') || (n == '#' && r.Peek() == '#'))
						{
							r.ReadLine();
							
							if(n == '#')
							{								
								if(isTargetCode)
								{
									l.Add(new Tuple<string,string>(rawCode, sb.ToString().Trim()));
									sb.Clear();
								}
								else
								{
									rawCode = sb.ToString().Trim();
									sb.Clear();
								}
								
								isTargetCode = !isTargetCode;
							}
						}
						else if(n == '\r' || n == '\n')
						{
							sb.Append((char)n);
						}
						else
						{
							sb.Append((char)n);
							sb.AppendLine(r.ReadLine());
						}
					}
				}
			}
			
			foreach(var tup in l)
			{
				Fmt(tup.Item1, tup.Item2, o);
			}
		}
开发者ID:DinrusGroup,项目名称:D_Parser,代码行数:54,代码来源:FormatterTests.cs

示例15: CountProteins

        public static int CountProteins(FileStream proteinFastaDatabase, bool onTheFlyDecoys, out int targetProteins, out int decoyProteins, out int onTheFlyDecoyProteins)
        {
            targetProteins = 0;
            decoyProteins = 0;
            onTheFlyDecoyProteins = 0;

            StreamReader fasta = new StreamReader(proteinFastaDatabase);

            string description = null;

            while(true)
            {
                string line = fasta.ReadLine();

                if(line.StartsWith(">"))
                {
                    description = line.Substring(1);
                }

                if(fasta.Peek() == '>' || fasta.Peek() == -1)
                {
                    if(description.Contains(Protein.DECOY_IDENTIFIER))
                    {
                        if(onTheFlyDecoys)
                        {
                            throw new ArgumentException(proteinFastaDatabase.Name + " contains decoy proteins; database should not contain decoy proteins when \"create target–decoy database on the fly\" option is enabled");
                        }
                        decoyProteins++;
                    }
                    else
                    {
                        targetProteins++;
                        if(onTheFlyDecoys)
                        {
                            onTheFlyDecoyProteins++;
                        }
                    }

                    description = null;

                    if(fasta.Peek() == -1)
                    {
                        break;
                    }
                }
            }

            proteinFastaDatabase.Seek(0, SeekOrigin.Begin);

            return targetProteins + decoyProteins + onTheFlyDecoyProteins;
        }
开发者ID:nfillmore,项目名称:morpheus_speedup,代码行数:51,代码来源:ProteinFastaReader.cs


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