Hi, I am making a Binary Reader find then read a string and input it into a textbox. I have 2 questions. I need to search for a string and read the string a byte afterwards. The string I am reading can be 1 - 4 bytes long. It is offset between "". (Two quotes [it is inside])
1) Is there a way I can make it find a string faster because right now on large files it just locks up.
2) What is wrong with this code, I keep catching these errors.
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "All Files|*.*";
ofd.Title = "Open Profile";
ofd.FileName = "";
if (ofd.ShowDialog() == DialogResult.OK)
fileLocation = ofd.FileName;
//Searches for the clan tag
string search = "clanName ";
BinaryReader br = new BinaryReader(new FileStream(fileLocation, FileMode.Open, FileAccess.Read));
// Starting offset
br.BaseStream.Position = 0x14000;
string found = "";
try
{
// read next 65536 chars
found = new string(br.ReadChars(0x10000));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// Find our starting position in buffer
int index = found.IndexOf(search);
textBox1.Text = found.Substring(index, 20);
}