replaced boost functionality to find nth string occurences

This commit is contained in:
devZoGok
2024-10-10 20:30:25 +03:00
parent f7ea59259e
commit 341ada95b8
3 changed files with 17 additions and 7 deletions
+11
View File
@@ -90,4 +90,15 @@ namespace vb01{
return str;
}
int findNthOccurence(string &str, string occ, int occId, bool forward){
int occurenceId = (forward ? str.find(occ) : str.rfind(occ)), iteration = 0;
while(occurenceId != -1 && iteration != occId){
occurenceId = (forward ? str.find(occ, occurenceId + 1) : str.rfind(occ, occurenceId - 1));
iteration++;
}
return occurenceId;
}
}