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


C# StreamReader.ReadAllLines方法代码示例

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


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

示例1: TagConverter

        public TagConverter(ISettingsProvider settingsProvider)
        {
            using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.TagMappingFile)))
            {
                normalizedTags = reader
                    .ReadAllLines()
                    .Where(x => !string.IsNullOrWhiteSpace(x))
                    .Select(ParseTagDescription)
                    .ToDictionary(x => x.Name, x => x.RawTags);

                rawTagsMapping = normalizedTags
                    .SelectMany(normalizedTag => normalizedTag.Value.Select(rawTag => new { Normalized = normalizedTag.Key, Raw = rawTag }))
                    .ToDictionary(x => x.Raw, x => x.Normalized);
            }

            using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.CorrectionsFile)))
            {
                correctionsByProblemUrl = reader
                    .ReadAllLines()
                    .Where(x => !string.IsNullOrWhiteSpace(x))
                    .SelectMany(ParseCorrections)
                    .GroupBy(x => x.ProblemUrl)
                    .ToDictionary(x => x.Key, x => x.ToArray());
            }
        }
开发者ID:BurlakovNick,项目名称:AcmProblemClassifier,代码行数:25,代码来源:TagConverter.cs

示例2: DTDParser

 public DTDParser(string sourcedir)
 {
   ofdGetDTDName.InitialDirectory = sourcedir;
   ofdGetDTDName.Multiselect = false;
   ofdGetDTDName.CheckFileExists = true;
   ofdGetDTDName.DefaultExt = ".dtd";
   ofdGetDTDName.Filter = @"DTD XML specifikáció (*.dtd)|*.dtd";
   if (ofdGetDTDName.ShowDialog() == DialogResult.Cancel)
   {
     dtdFileName = sourcedir + @"17\appshelldata.dtd";
   }
   else
   {
     dtdFileName = ofdGetDTDName.FileName;
   }
   if ( !File.Exists(dtdFileName ))
   {
     throw new ArgumentException("A megadott fájl nem létezik!!!! -> Objektum nem létrehozható");
   }
   StreamReader dtdReader = new StreamReader(dtdFileName);
   dtdLines = dtdReader.ReadAllLines((x) => { return Regex.IsMatch(x,@"^<!ENTITY");}) ;
   foreach ( string ln in dtdLines )
   {
     Match regMatch = Regex.Match( ln, @"(?<qtn>qtn_\w+)\s+" + "\"" + @"(?<kifejt>[^" + "\"" + @"]+)" + "\"" );
     struParser ParserRec = new struParser
     {
       strKifejt = regMatch.Groups["kifejt"].Value,
       strRegex = @"\&"+regMatch.Groups["qtn"].Value+";"
     };
     myParser.Add( ParserRec );
   }
 }
开发者ID:flaithbheartaigh,项目名称:nokias60cenrepeditor,代码行数:32,代码来源:S60.Plugin.MenuEditor.cs

示例3: StopWordsFilter

 public StopWordsFilter(ISettingsProvider settingsProvider)
 {
     var stopwordsFile = settingsProvider.Get<string>(SettingsKeys.StopwordsFile);
     using (var reader = new StreamReader(stopwordsFile))
     {
         stopwords = new HashSet<string>(reader.ReadAllLines());
     }
 }
开发者ID:BurlakovNick,项目名称:AcmProblemClassifier,代码行数:8,代码来源:StopWordsFilter.cs

示例4: Main

        static void Main(string[] args)
        {
            //JSON file with one line per tweet.
            string rawPath = @"D:\Andrew Hardin\Desktop\coastal_users_better.txt";

            //Load the users.
            User[] Users;
            using (StreamReader rdr = new StreamReader(rawPath))
            {
                Users = rdr.ReadAllLines().Select(x => new User(x)).ToArray();
            }

            //Only select the reliable users.
            User[] Reliable = Users.Where(x => x.Reliable).ToArray();

            //Writeout diagnostics.
            string Base = Path.GetDirectoryName(rawPath);
            WriteDistanceList(Base + @"\TriangleDistances.csv", Reliable);
            WriteUserKML(Base + @"\diagnostic.kml", Reliable);
            WriteMultipoint(Base + @"\ImportToArcmap.csv", Reliable);
        }
开发者ID:jenningsanderson,项目名称:GIS3-Sandy-Project,代码行数:21,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            //the first argument is the words file, or the default words.txt file if no arguments are given
            var wordsFile = args.Length == 0 ? DEFAULT_WORDS_FILE : args[0];

            //read in the words from file
            string[] words;
            using (TextReader reader = new StreamReader(wordsFile))
                words = reader.ReadAllLines();

            //frequency of each letter, called 'r' in the psuedo-code
            int[] freqs = new int[26];

            //symmetric digraph frequencies, called 'd' in the psuedo-code
            int[,] sdFreqs = new int[26, 26];

            //calculate frequencies
            foreach (var word in words)
                for (int i = 0; i < word.Length; i++)
                {
                    //skip words with hyphens -- just an issue with my default word dictionary
                    if (word.Contains('-'))
                        continue;

                    //get the array index of this character
                    int cur = word[i] - 'a';

                    //increment the overall frequency of this letter
                    freqs[cur]++;

                    //increment the frequency of the current character following the previous character
                    if (i > 0)
                    {
                        int prev = word[i - 1] - 'a';
                        sdFreqs[cur, prev]++;

                        //we're generating a symmetric matrix, so we need to increment the other
                        //side unless we're on the diagnol
                        if (cur != prev)
                            sdFreqs[prev, cur]++;
                    }
                }

            //calculate the letter with maximum frequency, called 'r.m' in the psuedo-code
            int maxFreq = 0;
            for (int i = 0; i < freqs.Length; i++)
                if (freqs[maxFreq] < freqs[i])
                    maxFreq = i;

            //The stack of vowels to find
            Stack<int> v = new Stack<int>();

            //calculate the vowels
            while (freqs[maxFreq] > 0)
            {
                //the highest frequency letter is a vowel
                v.Push(maxFreq);

                //the next maximum frequency to find, called 'j' in the psuedo-code
                int nextMaxFreq = 0;

                //remove all occurences of the current vowel
                for (int i = 0; i < freqs.Length; i++)
                {
                    if (i != maxFreq)
                        freqs[i] -= 2 * sdFreqs[i, maxFreq];
                    else
                        freqs[i] = 0;

                    if (freqs[nextMaxFreq] < freqs[i])
                        nextMaxFreq = i;
                }

                maxFreq = nextMaxFreq;
            }

            //print out the results
            Console.WriteLine("Vowels found are:");
            foreach (var i in v)
                Console.WriteLine((char)('a' + i));
        }
开发者ID:tansey,项目名称:sukhotin,代码行数:81,代码来源:Program.cs

示例6: GetRandomWords

        /// <summary>
        ///     Randomly selects words between <see cref="MinWordLength" /> characters and <see cref="MaxWordLength" /> characters
        ///     in length, inclusive,
        ///     from the word list.
        /// </summary>
        /// <param name="reader">A <see cref="StreamReader" /> for the word list.</param>
        /// <returns>A number of random words meeting the word length limitations specified by the configuration.</returns>
        private IEnumerable<string> GetRandomWords(StreamReader reader)
        {
            #if DEBUG
            Debug.WriteLine(string.Format("Processing wordlist to get words between {0} and {1} chars",
                                          this.MinWordLength,
                                          this.MaxWordLength));
            Stopwatch sw = Stopwatch.StartNew();
            #endif //DEBUG

            IEnumerable<string> suitableWords =
                reader.ReadAllLines()
                      .Where(w => (w.Length >= this.MinWordLength) && (w.Length <= this.MaxWordLength))
                      .ToList();

            #if DEBUG
            sw.Stop();
            Debug.WriteLine(string.Format("Done in {0}", sw.Elapsed));
            #endif //DEBUG

            for (int i = 0; i < this.WordCount; i++)
            {
                yield return suitableWords.ElementAt(this.RandomSource.Next(0, suitableWords.Count()));
            }
        }
开发者ID:JohnBloom,项目名称:xkpassword,代码行数:31,代码来源:XkPasswd.cs


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