1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-05-31 08:31:41 +05:30

D: add countLettersInTextFile.d

This commit is contained in:
2024-01-31 20:00:17 +03:00
parent f5fd670db6
commit a8f909d1a9
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
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()
{
auto fileContent = cast(string)read("file.txt");
auto totalLetters =
count(filter!(a => isAlpha(a) || isWhite(a))(fileContent));
auto percentage = (totalLetters * 100) / cast(double)fileContent.length;
writefln("Percentage of letters: %.0f", percentage);
}