View Single Post
Old 04-01-2008, 09:04   #9
trallallero
Senior Member
 
L'Avatar di trallallero
 
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
Quote:
Originariamente inviato da cionci Guarda i messaggi
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 "";
}
////////////////////////////////////////////////////////////////////
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z Mb - Win Eight SP (1 > yours) 16 Valve
trallallero è offline   Rispondi citando il messaggio o parte di esso