Created
June 23, 2019 21:36
-
-
Save mshwf/098d0a86c7f68a0b7904bf6dbaf7420e to your computer and use it in GitHub Desktop.
finds occurrences of a sub-string in a string
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
List<Kmer> kmers = new List<Kmer>(); | |
string message = "gjhcebfu71uevkkvhjv,yjvykku71jrbirbgerngtgntteu71agg6g79htu718eay8hibioay+8eru71ohob8vy89egyhoih89vu71oyhbigr89yhrrvoaeoghau71e8ryg98ergh.oaeryl9g7rv7g7iytg643483gi@$#t32@#2R23r213ri4tyg2ti.88oichu71tp9hg"; | |
for (int i = 0; i <= message.Length - 3; i++) | |
{ | |
string substring = message.Substring(i, 3); | |
int occurences = Regex.Matches(message, Regex.Escape(substring)).Count; | |
kmers.Add(new Kmer { Text = substring, Occ = occurences }); | |
} | |
foreach (var kmer in kmers.OrderByDescending(k => k.Occ).ThenByDescending(k => k.Text).Distinct(new KMerQualty())) | |
{ | |
Console.WriteLine($"{kmer.Text}=>{kmer.Occ} times"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment