Answers for "c++ count number of substrings"

C++
1

string count occurrences c++

#include <algorithm>

std::string s = "a_b_c";
size_t n = std::count(s.begin(), s.end(), '_'); //n=2
Posted by: Guest on April-18-2021
0

how to know the number of a certain substring in a string in c++

int nPos = str_to_search.find(str, 0); 
while (nPos != string::npos)
{
	count++;
	nPos = str_to_search.find(str, nPos + str.size());
}
Posted by: Guest on September-13-2021

Code answers related to "c++ count number of substrings"

Browse Popular Code Answers by Language