Quote:
Originariamente inviato da cionci
Appunto...basta lavorare esclusivamente con le string e sei a posto...poi se devi usare qualche libreria che ha come parametri char * basta convertire con c_str().
|
scusa se insisto ma a questo punto vorrei sapere come faresti questa funzione senza l'uso di un rapido
strchr.
È una funzione che cerca una stringa delimitata da certi caratteri in una stringa sorgente. Ho usato sia string che funzioni C
All'inizio pSrc era di tipo string& poi ho sbroccato (non ricordo perchè ma per colpa di 'ste string) ed ho messo char*
Codice:
string LLUtils::GetDelimitedString( const char* pSrc, int LeftDelimiter, int RightDelimiter )
{
LogL.Write( LogLib::LOGLIB_DEBUG_FLOW_MSG, LOGLIB_FIX_ARGS, 0, "" );
if (pSrc) // so the caller can avoid checking
{
char* start = strchr( pSrc, LeftDelimiter );
if (start) // left delimiter was found
{
while(*(++start) == ' ')
; // skip left spaces
char* end = strchr( start, RightDelimiter );
if (end) // right delimiter was found
{
while(*(--end) == ' ')
; // skip right spaces
string s(pSrc); // create the string to be returned
s.substr( (start - pSrc) );
return s.substr( (start - pSrc), (end - start + 1) );
}
}
}
return "";
}
////////////////////////////////////////////////////////////////////