Here is an example of a std::string function that finds a string between strings
Code:
#include <iostream>
#include <string>
std::string StringBetween(const std::string &findString, const std::string startString, const std::string endString)
{
//Grab the length of the first string for moving the index
size_t startLength = startString.length();
size_t endLength = endString.length();
//Sanity Check: Cannot find between empty strings
if(0 == startLength || 0 == endLength){
return "";
}//if
//Find the index of the first string
size_t startIndex = findString.find(startString);
//If we can't find that string return blank
if(std::string::npos == startIndex){
return "";
}//if
//Increment the start index to get the contents between
startIndex = startIndex + startLength;
//Find the index of the end string
size_t endIndex = findString.find(endString, startIndex);
//If we can't find it return blank
if(std::string::npos == endIndex){
return "";
}//if
//We found our string within our indexes return it back
return findString.substr(startIndex, endIndex - startIndex);
}
int main()
{
//The string to search between
std::string findString = "abcdefghi";
//The string that will contain the items between strings
std::string subString = StringBetween(findString, "abc", "ghi");
//Output the result
std::cout<<subString;
//"Wait" for input
std::cin.get();
}