1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-25 08:09:45 +05:30

D: add countLettersInTextFile.d

This commit is contained in:
Intel A80486DX2-66 2024-01-31 20:00:17 +03:00
parent f5fd670db6
commit a8f909d1a9
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
2 changed files with 49 additions and 0 deletions

33
.gitignore vendored
View File

@ -1,6 +1,7 @@
# ---> C
# Prerequisites
*.d
!d-programming/**.d
# Object files
*.o
@ -213,3 +214,35 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# ---> D
# Compiled Object files
*.o
*.obj
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Compiled Static libraries
*.a
*.lib
# Executables
*.exe
# DUB
.dub
docs.json
__dummy.html
docs/
# Code coverage
*.lst
# Swap files of editors
*.*~
# Build directory
build/

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);
}