Created
December 12, 2019 23:49
-
-
Save dojekon/7e6d4cc0b2b796c8cad38dc4bf6cb2c9 to your computer and use it in GitHub Desktop.
Text frequency analysis C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Alphabet = Enumerable.Range('А', 32).Select(x => (char)x).ToArray(); | |
string txt = Regex.Replace(text, "[#-.?!)(,: ]", ""); | |
txt = txt.ToUpper(); | |
Dictionary<char, double> Analysis = new Dictionary<char, double>(); | |
int count = 0; | |
for (int i = 0; i < Alphabet.Length; i++) { | |
count = 0; | |
foreach (char letter in txt) { | |
if (letter == Alphabet[i]) | |
count++; | |
} | |
if (count > 0) { | |
Analysis.Add(Alphabet[i], Math.Round(((double)count / txt.Length),2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment