Well a simple method would be to start by finding each occurance of the first character of the substring in the string, then at each occurance check to see if the substring exists there.
U can have a string say, "Hi", and memcmp it with from the start of each letter of the main string, I suggest u not to use strcmp becoz if at all ur string contains a numerical zero then u could end up with errors.
This example uses coldfusion but the same technique can be used in most languages... I simply compare the length of the original string with the length of the string with my search string stripped out. I then divide the difference by the length of the search string. This is a fast and neat technique. (Note: The algorithm will find 3 occurrences of "IS" which is correct, if you want to use spaces like this, " IS ", it will find 2 occurrences)
MichaelMcKavanagh
<email removed>
<cfset originalStr = " THIS IS A FUNNY TEST IS IT NOT " >
<cfset searchStr = "IS" >
Now that I`ve had another look at this, my thread # 8 is very unhelpfull (or plain wrong) and should be scratched
If the string is in a char array and you traverse it with a for loop, the statement in the body of this loop:
@whodgson
Why not simply use 'H' and 'i' instead of those magic numbers? Your code will fail miserably on any non ASCII encoding computer. Don't use magic numbers, never.