1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-24 13:49:46 +05:30
gists/d-programming/countLettersInTextFile.d

16 lines
448 B
D
Raw Permalink Normal View History

2024-01-31 22:30:17 +05:30
import std.algorithm.iteration : filter;
import std.algorithm.searching : count;
import std.ascii : isAlpha, isWhite;
import std.file : read;
import std.stdio : writefln;
void main(string[] argv)
2024-01-31 22:30:17 +05:30
{
auto fileContent = cast(string)read(argv[1]);
2024-01-31 22:30:17 +05:30
auto totalLetters =
count(filter!(a => isAlpha(a) || isWhite(a))(fileContent));
auto percentage = (totalLetters * 100) / cast(double)fileContent.length;
writefln("Letters: %.0f%%", percentage);
2024-01-31 22:30:17 +05:30
}