AnagramHashBag.MyTest.ReadFileWords C# (CSharp) Method

ReadFileWords() public static method

public static ReadFileWords ( String filename, int n ) : System.Collections.Generic.IEnumerable
filename String
n int
return System.Collections.Generic.IEnumerable
        public static SCG.IEnumerable<String> ReadFileWords(String filename, int n)
        {
            Regex delim = new Regex("[^a-zæøåA-ZÆØÅ0-9-]+");
            Encoding enc = Encoding.GetEncoding("iso-8859-1");
            using (TextReader rd = new StreamReader(filename, enc))
            {
                for (String line = rd.ReadLine(); line != null; line = rd.ReadLine())
                {
                    foreach (String s in delim.Split(line))
                        if (s != "")
                            yield return s.ToLower();
                    if (--n == 0)
                        yield break;
                }
            }
        }