Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find the second aperrence of a char in string c++

#include <string>

int nthOccurrence(const std::string& str, const std::string& findMe, int nth)
{
    size_t  pos = 0;
    int     cnt = 0;

    while( cnt != nth )
    {
        pos+=1;
        pos = str.find(findMe, pos);
        if ( pos == std::string::npos )
            return -1;
        cnt++;
    }
    return pos;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #aperrence #char #string
ADD COMMENT
Topic
Name
5+4 =