DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

C++ String Count Substring

07.24.2009
| 5287 views |
  • submit to reddit
        // description of your code here

unsigned int str_count(const string &text ,const string &str)
{
        unsigned int count=0;
        string::size_type pos=text.find(str);
        while(pos!=string::npos)
        {
                count++;
                idx=text.find(str,pos+1);
        }
        return count;
}