M
mojobojo
Enthusiast
I made this code to search for an ASCII String bit it is pretty slow. Is there a faster way to do this. Im thinking my code isnt wrong but needs some modifications. Im still trying modifications to this code.
Code:
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]FileStream[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] fs = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]FileStream[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](fileName, [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]FileMode[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Open);[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]BinaryReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] br = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]BinaryReader[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](fs);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] found = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] i = 0; i < fs.Length; i++)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2] br.BaseStream.Position = i;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] str = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Encoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ASCII.GetString(br.ReadBytes(toSearch.Length));[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (toSearch == str)[/SIZE]
[SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] MessageBox[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Show([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Found at: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i.ToString([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"X2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));[/SIZE]
[SIZE=2] found = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (found == [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af] MessageBox[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Show([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Not Found"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]br.Close();[/SIZE]
[SIZE=2]fs.Close();[/SIZE]