Hey all,
I was wondering about this piece of code on how to make it simpler to find the needle in the haystack for example "abbaabbaabb", "abba" - the needle, "abba" is found 2 times in the haystack "abbaabbaabb".
I have this code:
unsigned int substringCount(const std::string& strng, const std::string& subStrng)
{
if (subStrng.length() == 0)
{
cout << "There is nothing in your string" << endl;
return 0;
}
else
{
int count = 0;
for (size_t offset = strng.find(subStrng); offset != std::string::npos;offset = strng.find(subStrng, offset + subStrng.length() ) )
{
++count;
}
return count;
}
}
BUT it would be great if it was simplified because to be honest I have no idea what is going on here...
Thanks! :)