ESEMPIO:
codice:
#include <iostream>
#include <string>
using namespace std;
string find_pat(string where, int * pos, string start, string end);
int main()
{
int pos=0;
string t;
string s = "<inizio>...</fine>bla bla bla <inizio>\?\?\?</fine>";
while((t=find_pat(s, &pos, "<inizio>", "</fine>")) != "")
cout << t << endl;
return 0;
}
string find_pat(string where, int * pos, string start, string end)
{
int pos2, pos3;
int work=1;
pos2=*pos;
while(work)
{
pos2 = where.find (end, pos2);
if(pos2 == string::npos) return string("");
pos3 = where.rfind (start, pos2);
if(pos3 == string::npos || pos3 < *pos)
{
pos2 = pos2 + end.length() ;
}
else
{
pos3 += start.length();
work=0;
}
}
*pos=pos2+end.length();
return where.substr (pos3, pos2-pos3);
}