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:
parent
f5fd670db6
commit
a8f909d1a9
33
.gitignore
vendored
33
.gitignore
vendored
@ -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/
|
||||
|
16
d-programming/countLettersInTextFile.d
Normal file
16
d-programming/countLettersInTextFile.d
Normal 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user