المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Search for repeated character combinations



C# Programming
09-08-2009, 04:30 PM
Hi everybody,

I have an tool that reads an file. That file has for example the follow content:


²{?ï#°?ùpO¬[?ùpO¬?ùpO¬??ùpO¬??ùpO*#?ùpO*N?

I would like to search for repeated character combinations like the bold characters. The character combination ùpO repeated 6 times.

I would like to return some top 5 with the most repeated character combinations. Something like this:

ùpO : 6 times
xyz : 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!