I have an tool that reads an file. That file has for example the follow content:
wvtnfhxyz1hdxyz1fdxyz1ejxyz1dhxyz1dxyz1eeaa1oeys
I would like to search for repeated character combinations like the bold characters. The character combination xyz1 repeated 6 times.
I would like to return some top 5 with the most repeated character combinations. Something like this:
xyz1 : 6 times
aa5 : 5 times
ab4 : 3 times
ab : 2 times
66 : 2 times
This is the code that reads the file:
Java
string path = @openFileDialog1.FileName;
try
{
// Open the stream and read it back.
using (FileStream fs = File.OpenRead(path))
{
byte[] b = new byte[1024];
//UTF8Encoding temp = new UTF8Encoding(true);
UTF7Encoding temp = new UTF7Encoding(true);
while (fs.Read(b, 0, b.Length) > 0)
{
textBox1.Text += temp.GetString(b);
}
}
}Thanks!

Roei BarRank #1,271 · 1.4K reputationPosted Sep 14, 2009, 11:54 AM EDT
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string _givenString = "wvtnfhxyz1hdxyz1fdxyz1ejxyz1dhxyz1dxyz1eeaa1oeys"; Dictionary _codes = new Dictionary(); int _startingPoint = 0; while (_startingPoint > _sortedCodes = SortDictionary(_codes); for (int i = 0; i > SortDictionary(Dictionary data) { List> result = new List>(data); result.Sort( delegate( KeyValuePair first, KeyValuePair second) { return second.Value.CompareTo(first.Value); } ); return result; } } }it would be easier in Linq but hope this helps
khalid Johnson9 reputationPosted Sep 15, 2009, 4:26 AM EDT
Thanks for your support! I have test it, but why is the output inconsistent? In the example below you can see that the character combination ab 34 times occurs instead of 4 times. And is it possible to add an parameter combinationWidth to search only at character combinations with the combinationWidth value.
example
Thank you.