Skip to content

Instantly share code, notes, and snippets.

@dojekon
Created December 12, 2019 23:49
Show Gist options
  • Save dojekon/7e6d4cc0b2b796c8cad38dc4bf6cb2c9 to your computer and use it in GitHub Desktop.
Save dojekon/7e6d4cc0b2b796c8cad38dc4bf6cb2c9 to your computer and use it in GitHub Desktop.
Text frequency analysis C#
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