I would like to know how to count how many times a string is repeated within another string in C++.
I have only found ways to count repetition but only for one character.
What I would like would be that, for example, if I have a string p="AJAJDJSDJSDJNBDSJJAJSDKANSDKKSJAJSJSJSDAANSJDANSNADNAS", what I would like to do is know how many "AJA" there are, how many "JSKA" there are, how many "DANSN" there are... in that string p.
The only similar thing I have found and have done is the following:
#include <iostream>
#include<string>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
string string1="NLNNCCCL";
string string2="CCCL";
if (string1.find(string2) != std::string::npos) {
std::cout << "se encontró!"<<endl;
}
system("pause");
return 0;
}
But in that code I only ensure the existence of the typed pattern (string2) but not the times it is repeated in string1