Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

cpp string find all occurence

string str,sub; // str is string to search, sub is the substring to search for

vector<size_t> positions; // holds all the positions that sub occurs within str

size_t pos = str.find(sub, 0);
while(pos != string::npos)
{
    positions.push_back(pos);
    pos = str.find(sub,pos+1);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #cpp #string #find #occurence
ADD COMMENT
Topic
Name
5+9 =