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.
Hi,
I have another string handling question for the group, since you have all
been so helpful in the past. Thank you.
Basically, I want to do something really simple:
Search a main...
When looking for a method to fetch unique elements and counting the
number of occurences of each of them, I found quite a lot of gross
examples of complex XSL. But after realizing the subtle...
Besides doing a loop is there a command that will give the number of
occurreneces of a chr in a string?
The only way I can think of is to do a while loop and count variable.
thanks for info
...
Hi
We have a rather large asp.net project with serveral utility projects
(written in C#). Is there at tool out there which can give an estimate of
the total amount of code lines all projects...
Hi all,
How can one count all the permutations of a substring in a string? For
a more concrete example, let's say
targetstr = 'AAA'
and
probestr = 'AA'
I want to consider how many times one...
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a
good description of how to count the frequency of different types of
poker hands using a mathematical approach. A sample...
How can I count the frequency of words in a ASCII File using STL?
a) I dont know what words will be found in the file
b) The max number of occurrences is 10,000 per word (in case that
matters)
...
Got this assignment due a few weeks later and since I am done with the up coming assignment, decided to try out the next one early rather than rush later. First part of it requires me to do a...
Im a newby to programing 2 months exp.. I am trying to write code in C to take a input string from the user and then the input substring. I wish to compare the substring to the string and count the...
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...