I have a string, for example: string cadena = "ABABBA";
and I want to know how many times the letter A is repeated next to the letter B , in the example I put in it I should result in 4 .
I had thought to use a for to traverse the string but that would only work with characters.
EDIT:
string frase = "ABABBA";
string palabra = "AB";
string palabra2 = "BA";
string nombre = "";
int cont = 0;
for (int i = 0; i < frase.Length; i++)
{
char caracter = frase[i];
nombre = nombre + caracter;
if (nombre.Contains(palabra) || nombre.Contains(palabra2))
{
cont++;
nombre = "";
}
}