void PluckField( char *str, char *dest, const char *delim, int part )
{
char *endpos;
char *startpos=str;
char *origstr=new char[strlen(str)];
strcpy(origstr, str); // save original string
if (!strlen(delim)) { strcpy(dest, str); return; }
for( int i=1; i
str=strstr(str, delim);
if(str==NULL)
{
// passed end of string
strcpy(startpos, origstr);
strcpy(dest, origstr);
return;
}
memcpy(str, &str[strlen(delim)], strlen(str)); // remove delim char
}
// find endposition of field
endpos=strstr(str, delim);
memset(dest, 0, sizeof(dest));
if( endpos==NULL )
strcpy(dest, str); // last field in string
else
memcpy(dest, str, endpos-str);
// restore original buffer
strcpy(startpos, origstr);
delete[] origstr;
}