Click here to Skip to main content
15,890,724 members
Home / Discussions / C#
   

C#

 
Questionstopping a waitcallback in a threadpool Pin
Jason Jerome6-Mar-10 12:18
Jason Jerome6-Mar-10 12:18 
AnswerRe: stopping a waitcallback in a threadpool Pin
Luc Pattyn6-Mar-10 16:25
sitebuilderLuc Pattyn6-Mar-10 16:25 
QuestionHow to search for a specific string in a file? Pin
SimpleData6-Mar-10 11:09
SimpleData6-Mar-10 11:09 
AnswerRe: How to search for a specific string in a file? Pin
StarBP6-Mar-10 11:17
StarBP6-Mar-10 11:17 
GeneralRe: How to search for a specific string in a file? Pin
SimpleData6-Mar-10 11:24
SimpleData6-Mar-10 11:24 
GeneralRe: How to search for a specific string in a file? Pin
StarBP6-Mar-10 11:28
StarBP6-Mar-10 11:28 
GeneralRe: How to search for a specific string in a file? Pin
SimpleData6-Mar-10 11:35
SimpleData6-Mar-10 11:35 
AnswerRe: How to search for a specific string in a file? [modified] Pin
harold aptroot6-Mar-10 11:32
harold aptroot6-Mar-10 11:32 
So what you want to do, is to find only 1 string once?
Because then you could just stream the file, no buffers needed.

[almost]
To visualize this (in case anyone needs the explanation); you can look at it like a state machine, with a state for every character in the string you are searching for (lets call it X). The state machine will keep reading 1 character at a time until it exits. It starts in state 0, and will change to state 1 if it reads a character that matches X[0]. State n will transition to state n+1 if it reads X[n] or to state 0 if it reads anything else. The last state will return the position in the file if it reads X[last]. Every state will return "not found" if it runs out of characters to read.
[/but not quite]

Solution: use the Knuth-Morris-Pratt algorithm, at worst it has to evaluate the same character multiple times, but it never needs to go back (only forward, but skipping characters in a stream is trivial)
Essentially it's doing the same as what I described, but it jumps back to the right state instead of always 0.

That way you only need a constant amount of memory plus the string X.
modified on Sunday, March 7, 2010 9:38 AM

GeneralRe: How to search for a specific string in a file? Pin
SimpleData6-Mar-10 11:35
SimpleData6-Mar-10 11:35 
GeneralRe: How to search for a specific string in a file? Pin
harold aptroot6-Mar-10 11:37
harold aptroot6-Mar-10 11:37 
GeneralRe: How to search for a specific string in a file? Pin
Luc Pattyn6-Mar-10 12:11
sitebuilderLuc Pattyn6-Mar-10 12:11 
GeneralRe: How to search for a specific string in a file? [modified] Pin
harold aptroot6-Mar-10 12:21
harold aptroot6-Mar-10 12:21 
GeneralRe: How to search for a specific string in a file? Pin
SimpleData7-Mar-10 4:05
SimpleData7-Mar-10 4:05 
GeneralRe: How to search for a specific string in a file? Pin
Luc Pattyn7-Mar-10 8:41
sitebuilderLuc Pattyn7-Mar-10 8:41 
GeneralRe: How to search for a specific string in a file? Pin
SimpleData7-Mar-10 8:47
SimpleData7-Mar-10 8:47 
GeneralRe: How to search for a specific string in a file? Pin
Luc Pattyn7-Mar-10 9:09
sitebuilderLuc Pattyn7-Mar-10 9:09 
GeneralRe: How to search for a specific string in a file? Pin
SimpleData7-Mar-10 9:11
SimpleData7-Mar-10 9:11 
AnswerRe: How to search for a specific string in a file? Pin
Shane55557-Mar-10 3:28
Shane55557-Mar-10 3:28 
QuestionPlease help as i cant remember how to do this..... Pin
stephen.darling6-Mar-10 10:41
stephen.darling6-Mar-10 10:41 
AnswerRe: Please help as i cant remember how to do this..... Pin
StarBP6-Mar-10 11:05
StarBP6-Mar-10 11:05 
GeneralRe: Please help as i cant remember how to do this..... Pin
stephen.darling6-Mar-10 11:35
stephen.darling6-Mar-10 11:35 
AnswerRe: Please help as i cant remember how to do this..... Pin
Alan N6-Mar-10 11:35
Alan N6-Mar-10 11:35 
GeneralRe: Please help as i cant remember how to do this..... Pin
stephen.darling7-Mar-10 8:56
stephen.darling7-Mar-10 8:56 
QuestionGDI+ P/Invoke Pin
StarBP6-Mar-10 10:15
StarBP6-Mar-10 10:15 
AnswerRe: GDI+ P/Invoke [modified] Pin
DaveyM696-Mar-10 10:21
professionalDaveyM696-Mar-10 10:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.