Reading a file of words line by line

mark mark at qtrac.eu
Wed Jan 15 19:50:31 UTC 2020


I really do need a set for the next part of the program, but 
taking your code and ideas I have now reduced the function to 
this:

WordSet getWords(string filename, int wordsize) {
     WordSet words;
     File(filename).byLine
	.map!(line => line.until!(not!isAlpha))
	.filter!(word => word.count == wordsize)
	.each!(word => words[word.to!string.toUpper] = 0);
     return words;
}

This is also 4x faster than my version that used a regex -- 
thanks!

Why did you use string.count rather than string.length?



More information about the Digitalmars-d-learn mailing list