-
string question?? help?
Hello,
I'm fairly new to C++ and am having some trouble and would appreciate any help. I have a string ex: "ATCTCAGCGTACCGTA". I want to be able to find all the positions that have "GTA", there's one at position 8 (counting from 0) and at 13, however whenever I use the find function included in the string library, it will only give me the place where the first such string is found, in this example being 8.
Is there any way I can use some other function or another way I can do this so that it will give me both the number 8 and 13, ad they are the places where "GTA" occurs. Any help will be greatly appreciated.. thanks
-
Code:
void PrintLocations(char* FullString, char* SubString)
{
int Position = 0;
int SubPosition;
bool Failed;
cout << "String: " << FullString << endl;
cout << "SubString: " << SubString << endl;
cout << "Matching positions: ";
while(Position < strlen(FullString))
{
SubPosition = 0;
Failed = false;
while(SubPosition < strlen(SubString))
{
if(((Position + SubPosition) >= strlen(FullString)) || (FullString[Position + SubPosition] != SubString[SubPosition]))
{
Failed = true;
}
SubPosition++;
}
if(!Failed) cout << Position << " ";
Position++;
}
}
-
thank you!!
Hello, thank you very much for the help...it was exactly what I was trying to do...thanks again!