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:
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!
khalid JohnsonPosted Sep 15, 2009, 8:26 AM
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.
Roei BarPosted Sep 14, 2009, 3:54 PM
it would be easier in Linq but hope this helps